我数据库中存在几个表:a,b,c,里面的字段都相同,但内容不同,表中有一个contact字段,我想把每个表中contact相同的整条记录取出来。请问这样的语句该怎样写?拜托了....

解决方案 »

  1.   

    select * from a where eixsts(select 1 from b where contact=a.contact)
      

  2.   

    ;with f as
    (
    select * from a where exists(select 1 from b where contact=a.contact)
    )
    select * from f where exists(select 1 from c where contact=c.contact)
      

  3.   

    select * from a,b,c where a.contact=b.contact and b.contact=c.contact
      

  4.   

    select contact from a
    union all 
    select contact from b
    union all
    ........這樣?
      

  5.   


    select *
    from a
    where exists (select 1 from b where a.contact = contact)
      and exists (select 1 from c where a.contact = contact)
      

  6.   

    我的意思是,假设a、b、c三个表中各有10条记录,a表中有3条记录contact="***",b表中有2条记录contact="***",c表中有1条记录contact="***",我现在想把这6条记录全部都取出来。用你们的方法好像只能得到一个表中的内容。
      

  7.   


    select * from a where contact='***'
    union all
    select * from c where contact='***'
    union all
    select * from b where contact='***'