论坛什么时候开的呀,我最近一直没打开,害得我很多问题都没有弄清楚。
话不多说,问题如下:
我有两张表TABLE A ,TABLE B
A表如下
ID NAME
1   a
2   b
3   c
4   d
... ...
B表如下
ID AID
1   2
2   3
... ...
B表的AID对应的是A表的ID号
我现在要得到的是两张表的数据,条件是排除B表的AID和A的ID相同的那几条数据
我是这样写的,可是总得不到我想要的数据
select a.ID as aid,a.NAME as aname from A a ,B b where b.AID NOT IN(SELECT c.ID as cid from A c)
可是总得不到我想要的,请问该怎么写????

解决方案 »

  1.   

    select a.ID as aid,a.NAME as aname from A a inner join B b on a.id<>b.aid  嘿嘿    沙发哦
      

  2.   

    select * from A where ID not in(select a.id from A a,B b where a.id=b.aid)
      

  3.   

    你测试过吗?我在SQLSERVER2000里得到的结果不是我想要的。
      

  4.   

    正解?
    明显把题目复杂化了
    select * from A where ID not in(select b.aid from B b)
      

  5.   

    select a.ID as aid,a.NAME as aname from A a full outer join B b on a.id = b.aid where a.id <> b.id