wispas Posted January 28, 2010 Share Posted January 28, 2010 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 More sharing options...
CountryGirl Posted January 28, 2010 Share Posted January 28, 2010 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 https://forums.phpfreaks.com/topic/190133-seelcting-multiple-tables/#findComment-1003191 Share on other sites More sharing options...
wispas Posted January 28, 2010 Author Share Posted January 28, 2010 Fantastic... I will give it a try. Thanks! Link to comment https://forums.phpfreaks.com/topic/190133-seelcting-multiple-tables/#findComment-1003194 Share on other sites More sharing options...
hamza Posted January 29, 2010 Share Posted January 29, 2010 learn joins so you can better understand how to get data from 2 or more talbes Link to comment https://forums.phpfreaks.com/topic/190133-seelcting-multiple-tables/#findComment-1003863 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.