MySql表:likes
+----+---------+--------------+
| id | post_id | liked_by_uid |
+----+---------+--------------+
| 1 | 10 | 56 |
| 2 | 10 | 51 |
| 3 | 11 | 51 |
| 4 | 11 | 57 |
| 5 | 12 | 58 |
| 6 | 13 | 58 |
+----+---------+--------------+
uid
(56,57)的列表,因为他们喜欢我喜欢的帖子(10,11)。我可以使用两个查询
SELECT post_id FROM likes WHERE liked_by_uid='51' //51 is me
$ ids =“'10','11'”;从第一个查询获得
SELECT liked_by_uid FROM likes WHERE post_id IN($ids);
期望的uids(56,57)来自第二次查询
如何使用单一查询。
答案 0 :(得分:0)
SELECT liked_by_uid FROM likes WHERE post_id IN
(SELECT post_id FROM likes WHERE liked_by_uid='51')