exists 怎么用啊,
表 table1
id  name  bj
1    a    n
2    b    nid name bj
1   a    m
2   b    m
3   c    m
4   d    m
查询 表中 name不相等的那两条数据,,怎么写sqlselect id,name,bj from table1 aa where bj where bj='n' and not exists(select 1 from table1 bb where bj='m' and aa.id=bb.id )
高手指教下,,

解决方案 »

  1.   


    select id,name,bj from table1 aa where not exists(select * from table1 bb  where aa.id=bb.id ) 
      

  2.   

    SQL> select *
      2    from table2 a
      3   where not exists (select 1 from table1 b where a.name = b.name)
      4  ;        ID NAME       BJ
    ---------- ---------- ----------
             4 d          m
             3 c          m
      

  3.   

    id  name  bj 
    1    a    n 
    2    b    n id name bj 
    1  a    m 
    2  b    m 
    3  c    m 
    4  d    m -- 这个是一个表的数据还是两个表的数据?
      

  4.   

    是一个表的 很多bj数据  我就想比n 和m的
      

  5.   

    select id,name,bj from table1 aa where bj where bj='n' and not exists(select 1 from table1 bb where bj='m' and aa.id=bb.id ) 
    其实我的 n 和m 颠倒一下就对了 有先后顺序