根据我的测试,三个表的全连接,
用select a.*,b.*,c.* from a,b,c where a.id=b.id and b.id=c.id 应该是不对的
再加上一个 a.id=c.id 也不对应该怎么写呢

解决方案 »

  1.   

    SQL server的连接语法在Oracle里面也能行得通。给点数据,然后列出你要的结果,帮你看如何写SQL
      

  2.   

    sorry,写错了,不是全连接,是内连接,题目为准
      

  3.   

    就比如现有表
    A: id ,value1
       1   '1'
       1   '2'
    B: id ,value2
       1, '3'
    c: id ,value3
       1, '4'想得到值为:
      id,value1,value2,value3
      1  '1'    '3'    '4'
      1  '2 '   '3'    '4'
      

  4.   

    select a.*,b.* from mzsf_data a,mzcfzjl_data b where a.id=b.id
    and 
    exists
    (select c.xm from ghxx c where a.id=c.id)
      

  5.   


    select a.*,b.* from mzsf_data a,mzcfzjl_data b where a.id=b.id
    and 
    exists
    (select c.id from ghxx c where a.id=c.id)
    and 
    exists
    (select c.id from ghxx c where b.id=c.id)
      

  6.   


    SQL> select * from a;                                     ID VALUE1
    --------------------------------------- --------------------
                                          1 1
                                          1 2SQL> select * from b;                                     ID VALUE2
    --------------------------------------- --------------------
                                          1 3SQL> select * from c;                                     ID VALUE3
    --------------------------------------- --------------------
                                          1 4SQL> 
    SQL> select a.id,a.value1,b.value2,c.value3 from a cross join b,c;                                     ID VALUE1               VALUE2               VALUE3
    --------------------------------------- -------------------- -------------------- --------------------
                                          1 1                    3                    4
                                          1 2                    3                    4
      

  7.   

    用子查询的写法,先连接其中两表,得出的数据集再和第三个表相连
    select t.*,c.* from (select a.*,b.* from a,b where b.id = b.id)t,c 
    where t.id=c.id 
      

  8.   

    SQL> with a as (select 1 id,'1' value from dual
      2             union
      3             select 1 id,'2' value from dual
      4             ),
      5       b as (select 1 id,'3' value from dual),
      6       c as (select 1 id,'4' value from dual)
      7  select a.id,a.value,b.value value1,c.value value2 from a,b,c
      8  where a.id=b.id and a.id=c.id
      9  /
     
            ID VALUE VALUE1 VALUE2
    ---------- ----- ------ ------
             1 1     3      4
             1 2     3      4
     
    SQL> 
      

  9.   

    倒,发出的帖子不能修改的啊
    上面有点笔误:
    elect t.*,c.* from (select a.*,b.* from a,b where a.id = b.id)t,c 
    where t.id=c.id
      

  10.   

    select t.*,c.* from (select a.*,b.* from a,b where b.id = b.id)t,c 
    where t.id=c.id 
    不能明确定义列。我想过了
      

  11.   


    select a.*,b.*,c.* from a,b,c where a.id=b.id and b.id=c.id 有什么不对呢?
     SQL> with a as (select 1 id,'1' value from dual
      2             union
      3             select 1 id,'2' value from dual
      4             ),
      5       b as (select 1 id,'3' value from dual),
      6       c as (select 1 id,'4' value from dual)
      7  select a.id,a.value,b.value value1,c.value value2 from a,b,c
      8  where a.id=b.id and b.id=c.id
      9  /
     
            ID VALUE VALUE1 VALUE2
    ---------- ----- ------ ------
             1 1     3      4
             1 2     3      4这样很对呀,跟你在4楼的要求没有什么不符的。
      

  12.   


    但是如果value的值不止是1,2,3,4.
    可能到1000了呢,那应该怎么写呢
      

  13.   

    select a.*,b.*,c.* from a
    inner join b using(id)
    inner join c using(id)
      

  14.   

    注意一下关键字,using得不到想要的结果,
    就用 on(条件1 and (条件2 or 条件3)……),
    我经常要连接七、八张表
    有够变态的