如果你用的是mysql4.0以上版本
可以这样做
select a.col1 from a where col2 not in (select col2 from b)
如果你4.0以下版本
select a.col1 from a,b where a.col1<>b.col2
可以这样做
select a.col1 from a where col2 not in (select col2 from b)
如果你4.0以下版本
select a.col1 from a,b where a.col1<>b.col2
+----+------+
| id | name |
+----+------+
| 1 | t1.a |
| 2 | t1.b |
| 3 | t1.c |
| 4 | t1.d |
+----+------+
4 rows in set (0.00 sec)mysql> select * from t2;
+----+------+
| id | name |
+----+------+
| 1 | t2.a |
| 3 | t2.c |
+----+------+
2 rows in set (0.01 sec)mysql> SELECT t1.id,t1.name FROM t1,t2 where t1.id <> t2.id;
+----+------+
| id | name |
+----+------+
| 2 | t1.b |
| 3 | t1.c |
| 4 | t1.d |
| 1 | t1.a |
| 2 | t1.b |
| 4 | t1.d |
+----+------+
+----+------+------+------+
| id | name | id | name |
+----+------+------+------+
| 1 | t1.a | 1 | t2.a |
| 2 | t1.b | NULL | NULL |
| 3 | t1.c | 3 | t2.c |
| 4 | t1.d | NULL | NULL |
+----+------+------+------+t1的数据还是都出来了~~怎么才能不要2和4?