Jump to content

Seelcting multiple tables...


wispas

Recommended Posts

Can anyone help me... I am trying to write a SQL Query based on the following:

 

- I have two tables ( city, hotel )

- both have a id field and a field called city_code...

 

so what i need the query to do is get the id from the address bar (e.g $id=1 based off the city... ) and display all the city fields but also display all of the hotel that have the same 'city_code'.

 

so im guessing it will be WHERE hotel.city_code = city.city_code

 

Can someone please help as im so stuck at the moment.

Link to comment
https://forums.phpfreaks.com/topic/190133-seelcting-multiple-tables/
Share on other sites

Have you used joins? That's what you'll need.

 

For example:

 

SELECT * your_tablename.rowname, your_tablename2.rowname

FROM your_tablename

INNER JOIN (or you can use LEFT JOIN, RIGHT JOIN, depending on the need) your_tablename2 ON hotel.city_code=city.city_code.

 

then you can do your where statement.

 

Does that help at all?

 

Here's a link that may help: http://www.codinghorror.com/blog/archives/000976.html

 

 

Qadoshyah

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.