是否可以像这样进行查询?那有一些错误......
查询应检查用户是否确实使用q.id
回答了问题。
SELECT pictureid,
id,
points
FROM questions q
WHERE IF (q.id NOT IN (SELECT questions_id
FROM history h
WHERE h.users_id = 3))
答案 0 :(得分:7)
SELECT pictureid,id,points
FROM questions q
WHERE q.id NOT IN (
SELECT questions_id
FROM history
WHERE users_id = 3)
答案 1 :(得分:1)
是
SELECT pictureid,id,points
FROM questions q
WHERE q.id not in
(SELECT questions_id FROM history h WHERE h.users_id = 3);
答案 2 :(得分:1)
使用NOT EXISTS
也会解决使用NULL
的{{1}}问题
IN
如果您想使用IN执行此操作
SELECT pictureid, id, points
FROM questions q
WHERE NOT EXISTS
(
SELECT questions_id
FROM history h
WHERE h.questions_id = q.questions_id
AND h.users_id = 3
)