In this case, I have 3 tables: hotels, categories, hotel_category_infos.
Table "hotels": A list of all hotels.
-----------------------
| id | name |
-----------------------
| 1 | Hotel England |
| 2 | Hotel Scotland |
| 3 | Hotel Ireland |
| 4 | Hotel Norway |
-----------------------
Table "categories": A list of the accessibility categories (concerning a hotel's accessibility for handicapped people). Possible categories a hotel can be assigned to, even more than once.
--------------------------------------------------
| id | name |
--------------------------------------------------
| 1 | Ground floor without steps |
| 2 | Washing facilities wheelchair accessible |
| 3 | Special infrastructure on location |
--------------------------------------------------
Table "hotel_category_infos": The actual assignments of a category to a hotel, with an additional precise description for a category for this hotel.
-----------------------------------------------------------------------
| id | hotel_id | cat_id | description |
-----------------------------------------------------------------------
| 1 | 1 | 1 | No steps, except the one to the bla bla... |
| 2 | 1 | 2 | The entrance to the shower is 56cm wide... |
| 3 | 2 | 1 | The ramp at the entrance is 5% steep |
| 4 | 3 | 1 | Except on the terrace |
| 5 | 3 | 2 | Ask for rooms in the first floor |
| 6 | 3 | 3 | A indoor swimming pool is available for... |
-----------------------------------------------------------------------
What I would like to do:
In a search form all categories are listed as a checkbox, so after sending the form, I have an array with all the checked category-ids. I would like to list all hotels that have an assignment to every of these categories (not only one of them).
What I have tried:
e.g. select all hotels which have both additional information on "Ground Floor without steps" and "washing facilities"
SELECT
hotels.id
FROM
hotels INNER JOIN hotel_category_infos ON
hotel_category_infos.hotel_id = hotels.id AND
hotel_category_infos.cat_id IN (1,2)
But the IN()
-part suggests that only ONE of the categories must match, not both. What am I supposed to change in the SQL-statement?