表格request
包含外键字段job
和user
。我需要提取行的子集,其中一个用户同时拥有job
= 35和job
= 34的行。
此查询是否正确完成了工作?我相信它是。
SELECT * FROM `request`
WHERE `job` = 35 AND `fulfilled` is NULL
AND
`user` IN
(SELECT `user` FROM `request` WHERE `job` = 34 AND `fulfilled` is NULL )
答案 0 :(得分:7)
SELECT user
FROM request
WHERE job IN (34,35) AND `fulfilled` is NULL
GROUP BY user
HAVING COUNT(DISTINCT job) = 2