Reputation: 15
========================================================
I just want to get user who has both 2 and 14 in skills column. The answer should be "2"
Upvotes: 0
Views: 35
Reputation: 307
use this:
select seekerID from table_name where skillid="2" and seekerID = ( select author from table_name where skillid="14")
Upvotes: 0
Reputation: 72165
Try this:
SELECT seekerID
FROM mytable
WHERE skillID IN (2, 14)
GROUP BY seekerID
HAVING COUNT(DISTINCT skillID) = 2
DISTINCT
keyword is necessary only in case skillID
values can occur multiple times for a single seekerID
.
Upvotes: 1
Reputation: 44844
The easiest way to do this would be
select seekerID, count(*) as cnt
from table_name
where skillid in (2,14)
group by seekerID
having cnt = 2
Upvotes: 0