select id from table b where id not in table a

解决方案 »

  1.   

    select ID form table a where ID not in (select ID form table b)
    绝对正确的.
      

  2.   

    to :
    select ID form table a where ID not in (select ID form table b)
    绝对正确的.不能执行吧,在mysql里
      

  3.   

    当然可以执行的,我用的就是mysql,
    select ID form table b where ID not in (select ID form table a)
    你可以执行看.
      

  4.   

    我执行过了,过程如下:mysql> select * from a;
    +----+------+
    | id | name |
    +----+------+
    |  1 | a    |
    |  2 | b    |
    +----+------+
    2 rows in set (0.00 sec)mysql> select * from b;
    +----+------+
    | id | name |
    +----+------+
    |  1 | a    |
    |  2 | b    |
    |  3 | c    |
    +----+------+
    3 rows in set (0.00 sec)mysql> select id from b where id not in (select id from a);
    ERROR 1064: You have an error in your SQL syntax.  Check the manual that corresp
    onds to your MySQL server version for the right syntax to use near 'select id fr
    om a)' at line 1
    mysql>我的mysql的版本是4.0.20a-nt
      

  5.   

    对于求交集,我有了一个办法:
    select a.id, b.name from a, b where a.id=b.id
    说明,从a,b表中分别取一个字段,条件是他们的id相等。
      

  6.   

    交集是那样求,可你求的是补集呀,我在mysql的控制台执行的没有问题呀,我再看看.
      

  7.   

    windows下大小写可通用吧,况且我的表的字段都是小写的。
    哎,没辙了。
      

  8.   

    1.你可以将MYSQL升级到4.1以上的版本,那么支持
    select ID form table a where ID not in (select ID form table b)
    2.否则的话好象不能用一个SQL解决问题。