I have a page where I display all hotels in a certain area. Each hotel will have a number of rooms, each room having a number of beds. So the SUM() function should display the total number of beds for each hotel.
if the former, why would a room have more than one row in the rooms table?
No room has more than one row in the rooms table.
if the latter, why do you need to see any room columns at all?
SELECT h.hotel_id
, h.hotel_name
, h.address
, h.city
, h.state
, h.country
, h.zipcode
, h.phone
, r.total_beds
, hf.features_id
, hf.feature_name
, f.feature_description
FROM hotels AS h
INNER
JOIN ( SELECT hotel_id
, SUM(room_beds) AS total_beds
FROM rooms
GROUP
BY hotel_id ) AS r
ON r.hotel_id = h.hotel_id
INNER
JOIN hotels_features AS hf
ON hf.hotel_id = h.hotel_id
INNER
JOIN features AS f
ON f.features_id = hf.features_id
WHERE h.city = 'berlin'
you want the query to give the sum of all room beds for each hotel
so which room did you want to display as well? you had r.room_id, r.room_name, r.room_floor, r.room_number, and r.room_description in your query