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)
复制代码
我想取这2条查询结果的交集,请问SQL语句如何写。也就是结果id:1,4
SQL复制代码
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)