Jump to content

help with joins


zang8027

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.