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. Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/142871-help-with-joins/#findComment-748978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.