表结构:
id   A    B
1    123  456
2    789  456
3    456  123
4    789  123
———————————
如何查询出记录1和3
——————————
还是可以再程序中实现?

解决方案 »

  1.   

    select * from tb where id in(1,3)
      

  2.   

    select * 
    from tb m
    where  exists(select 1 from tb where A=m.B and B=m.A)
    貌似可以。给看看
      

  3.   

    select * from tb m
    where exists (select 1 from tb where a=b and B=m.A
      

  4.   

    select * from tb m
    where exists (select 1 from tb where a=b and B=m.A)