数据库中有这样的记录
table1
callno         username           companyid         biggroupid          smallgroupid
13760705651     test1              111111              11                   1
13760705652     test2              111111              22                   1
13760705653     test3              111111              11                   2
13760705654     test7              111112              11                   1
13760705655     test8              111112              11                   2
table2
biggroupid          companyid          biggroupname
11                   111111               大组一
12                   111111               大组二
22                   111111               大组三
33                   222222               大组四
table3
smallgroupid        biggroupid          smallgroupname
      1              11                  小组一
      2              11                  小组二
      3              22                  22大组一小组查询CompanyID为111111时显示的记录是这样子的
callno          usernam     biggroupname       smallgroupname
13760705651     test1         大组一                小组一
13760705652     test2         大组二             22大组一小组
13760705653     test3         大组一               小组二

解决方案 »

  1.   


    Select 
    A.callno,
    A.usernam,
    B.biggroupname,
    C.smallgroupname
    From table1 A
    Inner Join table2
    On A.biggroupid=B.biggroupid
    Inner Join table3
    On A.smallgroupid=B.smallgroupid
      

  2.   

    select
        A.callno,A.username,B.biggroupname,C.smallgroupname 
    from table1 A,table2 B,table3 C
    where
        A.companyid=B.companyid And A.biggroupid=B.biggroupid
        and A.smallgroupid=C.smallgroupname
    order by A.callno
      

  3.   

    上面有錯誤,改
    Select 
    A.callno,
    A.usernam,
    B.biggroupname,
    C.smallgroupname
    From table1 A
    Inner Join table2 B
    On A.biggroupid=B.biggroupid
    Inner Join table3 C
    On A.smallgroupid=C.smallgroupid
    Where A.companyid='111111'OrSelect 
    A.callno,
    A.usernam,
    B.biggroupname,
    C.smallgroupname
    From table1 A,table2 B,table3 C
    Where A.biggroupid=B.biggroupid And A.smallgroupid=C.smallgroupid And A.companyid='111111'
      

  4.   

    上面太多东东,不知道有没有看花眼,或者有打错字母的也不一定..呵呵~
    可以有两种写法:
    1>from 多表+where中条件限制
    2>使用内联接inner join 表连接,在on中设置表连接条件在2楼的贴子中答的是第一种方法,此为第2种select
        A.callno,A.username,B.biggroupname,C.smallgroupname 
    from table1 A inner join table2 B
    on A.biggroupid=B.biggroupid inner join table3 C
    on A.smallgroupid=C.smallgroupid
      

  5.   

    select * from 
    table1 t1 
    left  join table2 t2 on t1.biggroupid=t2.biggroupid and t1.companyid=t2.companyid
    left  join table3 t3 on t1.smallgroupid=t3.smallgroupid and t1.biggroupid=t3.biggroupid
    where t1.companyid='111111'
      

  6.   

    谢谢....
    oracle不支持 Inner 这些关健字的吗