Make in clause to match all items ot any alternative?

走远了吗. 提交于 2019-12-06 06:42:03

问题


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?


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!