我已经建立了一个查询,如下所示
SELECT *
FROM posts
WHERE postUserId IN (SELECT userB
FROM friends
WHERE userA = 1)
OR postUserId IN (SELECT userA
FROM friends
WHERE userB = 1)
AND postUserId NOT IN (2)
ORDER BY postId DESC
查询的所有行均显示我需要隐藏WHERE NOT IN
,但结果与预期不符
答案 0 :(得分:1)
您需要正确添加括号才能获得所需的结果
SELECT *
FROM posts
WHERE ( postUserId IN (SELECT userB
FROM friends
WHERE userA = 1)
OR postUserId IN (SELECT userA
FROM friends
WHERE userB = 1)
)
AND postUserId NOT IN (2)
ORDER BY postId DESC