select a.cd,b.cd,c.cd,d.cd,e.cd
from a,b,c,d,e
where a.cd=2 or b.cd=2 or c.cd=2 or d.cd=2 or e.cd=2;

解决方案 »

  1.   

    用联合查询union
    select cd from a union select cd from b union ……
      

  2.   

    unionselect cd from a
    union all
    select cd from b
    .....
      

  3.   

    select a.cd,b.cd,c.cd,d.cd,e.cd
    from a,b,c,d,e
    where a.cd=2 or b.cd=2 or c.cd=2 or d.cd=2 or e.cd=2;
      

  4.   

    unionselect cd from a
    union all
    select cd from b
    .....同意qiyousyc(沈阳棋友) 的,用UNION联合查询
      

  5.   

    anis0444() 的方法和使用union的方法,哪种效率高?
      

  6.   

    返回来一个值?是什么值,表名还是COUNT(*)?
      

  7.   

    select a.cd,b.cd,c.cd,d.cd,e.cd
    from a,b,c,d,e
    where a.cd=2 or b.cd=2 or c.cd=2 or d.cd=2 or e.cd=2;
      

  8.   

    or和union都是慢慢慢的,但这里好像只能这样写
      

  9.   

    select 
    是否存在=(case when 
    (
    select 1 from A where CD=2
    union 
    select 1 from B where CD=2
    union 
    select 1 from C where CD=2
    union 
    select 1 from D where CD=2
    union 
    select 1 from E where CD=2
    ) 1 then '存在' else '不存在' end
    )