SQL Command not working as expected Oracle
Does my SQL query below say it doesn't end properly on the first Inner Join? If I drop the second table and where clause then the query is good though?
SELECT homes.home_id, homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft,
listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features, home_type.type_name
FROM homes, bookings
WHERE bookings.booking_end < date '2013-01-23' OR bookings.booking_start > date '2013-01-22' AND bookings.home_id <> homes.home_id
INNER JOIN home_feature ON homes.home_id = home_feature.home_id
INNER JOIN home_type ON home_type.type_code = homes.type_code
INNER JOIN features ON home_feature.feature_id = features.feature_id
GROUP BY homes.home_id, homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft, home_type.type_name
Can anyone see the obvious errors in my request?
source to share
The sentence WHERE
is in the wrong place and you're mixing connection types:
SELECT homes.home_id,
homes.title, homes.description,
homes.living_room_count,
homes.bedroom_count,
homes.bathroom_count,
homes.price,
homes.sqft,
listagg(features.feature_name, '\n') WITHIN GROUP(ORDER BY features.feature_name) features,
home_type.type_name
FROM homes
INNER JOIN bookings
ON bookings.home_id = homes.home_id
INNER JOIN home_feature
ON homes.home_id = home_feature.home_id
INNER JOIN home_type
ON home_type.type_code = homes.type_code
INNER JOIN features
ON home_feature.feature_id = features.feature_id
WHERE bookings.booking_end < date '2013-01-23'
OR booking_start > date '2013-01-22'
GROUP BY homes.home_id, homes.title, homes.description,
homes.living_room_count, homes.bedroom_count,
homes.bathroom_count, homes.price, homes.sqft, home_type.type_name
The offer WHERE
appears after JOIN
and before GROUP BY
. Also, you must use one type of join syntax. You have used both explicit and implicit syntax. I have moved the join homes
and booking
in JOIN
instead of using comma between tables.
source to share