Skip to content
Advertisement

In the SQL Query I couldn’t get truly data

enter image description here

Hi, I have a facilities table. I want to know which hotel_id has 2 facilities at the same time.

with that no record.

Advertisement

Answer

Your query does not work because you are looking for rows that satisify both conditions simultaneously, which cannot happen. You need to look across rows of the same group.

Instead, you can filter on rows that satisfy either condition, and then ensure that you do have two rows per group:

If (hotel_id, facilities_id ) tuples are not unique, you need having count(distinct facilities_id) = 2 instead.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement