Hey i am trying to query my database tables that are set up in a many to many relationship with a table between. here is a quick erd of the tables in question
Homes ----< Home_Feature >---- Features
I have tried creating the below sql query but is there a way to return one row for each home instead of the many that are returned here? Or do do i have to change my table structures to accommodate a better solution?
SELECT homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, features.feature_name
FROM homes
INNER JOIN home_feature
ON homes.home_id = home_feature.home_id
INNER JOIN features
ON home_feature.feature_id = features.feature_id;
Output from query:
Title Feature ....
1 House A Balcony
2 House A Pool
3 House A Garage
4 House B Air-Con
Thank you, any help appreciated!
____________________EDIT__________________________
Hey i greatly appreciate the help you guys have given so far and was wondering if i could have a little more help with regards to adding to this query and selecting columns from another table.
When i simply add the column of the other table in the SELECT statement and the table in the FROM clause the query seems to not work? the query im using is below but doesn't work. Thanks again for the help.
SELECT homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft, home_type.type_name,
listagg(features.feature_name, ',') WITHIN GROUP (ORDER BY features.feature_name) features
FROM homes, home_type
INNER JOIN home_feature
ON homes.home_id = home_feature.home_id
INNER JOIN features
ON home_feature.feature_id = features.feature_id
GROUP BY homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft;
I get this error:
ORA-00904: "HOMES"."HOME_ID": invalid identifier
00904. 00000 - "%s: invalid identifier"