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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.