zang8027 Posted January 28, 2009 Share Posted January 28, 2009 I got 2 tables: table "hotels" hotel_id | hotel_name table "hotelsToCity" hotel_id | city_id Now, im using the following query to gain the hotel id from hotelsToCity: $quer3=mysql_query("SELECT DISTINCT hotel_id, city_id FROM hotelsToCity where city_id=$subcat ORDER BY city_id"); How can i use a join (inner or left.. idont know which is best to use) in that query. Link to comment https://forums.phpfreaks.com/topic/142871-help-with-joins/ Share on other sites More sharing options...
corbin Posted January 28, 2009 Share Posted January 28, 2009 SELECT DISTINCT htc.hotel_id, h.hotel_name, htc.city_id FROM hotelsToCity htc JOIN hotels h ON h.hotel_id = htc.hotel_id; You would want a LEFT JOIN if you want to pull records from hotelsToCity that do not have entries in the hotel table, but that shouldn't ever happen. Link to comment https://forums.phpfreaks.com/topic/142871-help-with-joins/#findComment-748978 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.