还有如果select 这个col取哪个表的col比较好?

解决方案 »

  1.   

    我的答案是
    select c.col.....where c.col = b.col
      and c.col = a.col
    ;顺便再问一下oracle中where以后的执行顺序是从后往前的,该怎么利用这个条件?
      

  2.   

    select * from A
    where A.col in
    (select B.col from B,C where B.col = C.col)
      

  3.   

    sorry,我忘记说了,我因为要取b和c的数,所以得 from a,b,c
      

  4.   

    关键是(记录数A远大于B远大于C)
      

  5.   

    select C.col,A.aaa,B.bbb
    from C join A on A.col = C.col
    join B on B.col = C.col
      

  6.   

    这样怎么样?select c.col.....where c.col = b.col
      and c.col = a.col
    ;
      

  7.   

    建议拿测试工具测一下(用你的大数据量)感觉你的这种方式,是把C和B有关系的取出来,C和A有关系的再取出来,然后再把两者的结果再进行比较,来取值!而Join方式呢,把C和A有关系的取出来之后,再到B中去找符合条件的!还是用测试出来的数据来说比较好!
      

  8.   

    我的答案是
    select *
    from a  join c on a.col = c.col join b a.col = b.col我感觉应该先用最大的表和最小的表产生结果集然后在和中间的表进行比较
      

  9.   

    我的测试结果SQL> select count(1)
      2  from an_user_base_file a
      3  join an_measure_pos b
      4  on a.user_no = b.user_no
      5  where a.bureau_code = '00'
      6  / COUNT(1)
    ---------
       158773 real: 8563
    SQL>  select count(1)
      2   from an_user_base_file a ,an_measure_pos b
      3   where  a.user_no = b.user_no
      4   and  a.bureau_code = '00'
      5  / COUNT(1)
    ---------
       158773 real: 11750
    SQL>  select count(1)
      2   from an_user_base_file a
      3   join an_measure_pos b
      4   on a.user_no = b.user_no
      5   where a.bureau_code = '00'
      6  / COUNT(1)
    ---------
       158773 real: 10953
    SQL> select count(1)
      2  from an_user_base_file a ,an_measure_pos b
      3  where  a.user_no = b.user_no
      4  and  a.bureau_code = '00'
      5  / COUNT(1)
    ---------
       158773 real: 8250
    SQL> select count(1)
      2  from an_user_base_file a
      3  join an_measure_pos b
      4  on a.user_no = b.user_no
      5  where a.bureau_code = '00'
      6  / COUNT(1)
    ---------
       158773 real: 7891
    SQL>