i have to agree, this is not a "beginner sql" question
it's more of a "sql 201" question, because the answer is not forthcoming with a simple SELECT
no matter how the beginner tries to write it, with ANDs and/or ORs, a simple query won't solve the problem
that's because we are actually looking for the presence of more than one (certain type of) row
damjan, you were so close, yes, you can do it with a self-join:
Code:
select t1.entity_id
from mapper t1
inner
join mapper t2
on t1.entity_id
= t2.entity_id
where t1.service_id = 5
and t2.service_id = 6
but this quickly becomes tedious as you want more values
the other way to do it is to select all the different qualifying rows, one by one, and then later, in the grouping, count how many different ones you got:
Code:
select entity_id
from mapper
where service_id in (5,6)
group
by entity_id
having count(distinct service_id) = 2
which is a lot easier to extend to 3, 4, 5 values...