Reputation: 21998
The table request
has foreign key fields job
and user
. I need to pull the subset of rows for which one user has both a row for both job
= 35 and job
= 34.
Is this query doing the job correctly? I believe it is.
SELECT * FROM `request`
WHERE `job` = 35 AND `fulfilled` is NULL
AND
`user` IN
(SELECT `user` FROM `request` WHERE `job` = 34 AND `fulfilled` is NULL )
Upvotes: 0
Views: 336
Reputation: 263723
SELECT user
FROM request
WHERE job IN (34,35) AND `fulfilled` is NULL
GROUP BY user
HAVING COUNT(DISTINCT job) = 2
Upvotes: 7