Make in clause to match all items ot any alternative?
-
20-06-2021 - |
Question
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?
Solution
select hotelid
from hotel_to_facilities_map
where facility_id in (3,5,2)
group by hotelid
having count(*) = 3
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow