假设有这样的表:
mysql> SELECT * FROM tags;
+---------+--------+
| post_id | tag_id |
+---------+--------+
| 1 | 2 |
| 1 | 3 |
| 1 | 1 |
| 2 | 1 |
| 2 | 2 |
+---------+--------+
5 rows in set (0.00 sec)
字段名称是不言自明的。我想选择post_id
同时具有 1 和 3tag_id
的 s,所以在这个例子中它只是1
. 我想到了类似
SELECT post_id FROM tags GROUP BY post_id HAVING ...
After have I'd like to list tag_id
s that are present in this group。我怎么做?