多次select查询结果的交集,请问SQL语句如何写
表A有2个字段id,aidmysql> select id from a where aid=5;+----+| id |+----+|1 ||2 ||4 |+----+3 rows in set (0.00 sec)mysql> select id from a where aid=6;+----+| id |+----+|1 ||4 |+----+2 rows in set (0.00 sec)
我想取这2条查询结果的交集,请问SQL语句如何写。也就是结果id:1,4
mysql> select id from a where aid=5;+----+| id |+----+|1 ||2 ||4 |+----+3 rows in set (0.00 sec)mysql> select id from a where aid=6;+----+| id |+----+|1 ||4 |+----+2 rows in set (0.00 sec)
条件and? mysql这垃圾不支持交集的。
如果是数据库那么SQL如下
SELECT id FROM a WHERE aid=5
INTERSECT
SELECT id FROM a WHERE aid=6
页:
[1]