I have a table hotel [hotelid,hotelname,etc]
and another table facilities[facilityid,facilityname]
these 2 tables are linked through table hotel_to_facilities_map[hotelid,facility_id]
so the table hotel_to_facilities_map
might contain values as
hotelid facility_id
-------------------
1 3
1 5
1 6
2 6
2 2
2 5
now i want to retrieve all the hotels which match ALL facilities asked for
select * from hotel_to_facilities_map where facility_id IN (3,5,2)
but this will cause the match as an OR
Expression while i need AND
.
is there any workaround or solution for this?
select hotelid
from hotel_to_facilities_map
where facility_id in (3,5,2)
group by hotelid
having count(*) = 3
来源:https://stackoverflow.com/questions/11430310/make-in-clause-to-match-all-items-ot-any-alternative