我有 3 个表要查询。我对第一个进行选择,具体取决于其他两个。我必须只有与第一个表不同的 id,但我的查询返回了一些重复项...... http://sqlfiddle.com/#!2/3e3d6/1
我的查询:
SELECT p.*
FROM posts p, blogs_subscribed s
WHERE (p.user_id = s.user_id OR p.user_id = 1)
AND p.id NOT IN (
SELECT post_id
FROM posts_unsubscribed u
WHERE u.post_id = p.id
AND u.user_id = p.user_id);
SELECT p.*
FROM posts p, blogs_subscribed s
WHERE (p.user_id = s.user_id OR p.user_id = 1)
AND NOT EXISTS(
SELECT null
FROM posts_unsubscribed u
WHERE u.post_id = p.id
AND u.user_id = p.user_id);
请问有什么想法吗?