MySQL 差集SELECT a. *
FROM table1 AS a
LEFT JOIN table2 AS b ON a.term = b.term
WHERE b.term IS NULL
上面这个可以查询出 a表和b表的差集但是我现在想要 b表中的部分行去和a表做 差集
我应该如何写条件!请高人指点。

解决方案 »

  1.   

    我不知道你的差集指的是什么.反过来写是不是?
    try:
    SELECT b. *
    FROM table2 AS b
    LEFT JOIN table1 AS a ON a.term = b.term
    WHERE a.term IS NULL
      

  2.   

    楼上应该不正确
    我是要先从b表中拿出一部分,然后才和a表做差集我写的只能得到到b表全部数据 和a表的差集
    你写的只能得到到a表全部数据 和b表的差集不知道写清楚了吗?
      

  3.   

    SELECT a. *
    FROM table1 AS a
    LEFT JOIN (select * from table2 where condition) as b ON a.term = b.term
    WHERE b.condition
    这样先到table2表里取出数据当作一个表来操作,不知道这样合不合你的意
      

  4.   

    我使用的是mysql 4.0
    好像不让使用LEFT JOIN (select * from table2 where condition) 原理应该是楼上的,但是不能执行
      

  5.   

    #1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select * from table2