表words
包含列:word_id
word
我的查询打印为:
SELECT word FROM words WHERE condition1 AND condition2 ORDER BY RAND() LIMIT 5000
表solved
包含列:user_id
word_id
我希望获取5000个随机行,条件是solved
user = username
中找不到任何行
到目前为止,我已尝试过:
SELECT word FROM words w
WHERE not exists
(select 1 from solved s where s.word_id = w.word_id
AND s.user_id = 'username')
AND condition1 AND condition2 ORDER BY RAND() LIMIT 5000
答案 0 :(得分:0)
将LEFT JOIN
用于thar:
SELECT word
FROM words w
left join solved s on s.word_id = w.word_id AND s.user_id = 'username'
WHERE w.word_id is null
AND condition1 AND condition2
ORDER BY RAND() LIMIT 5000