xcasio Posted January 4, 2010 Share Posted January 4, 2010 Hi, I need some help on a SELECT query. This is my table structure with only relevant fields: Table #1: interiors id (int) MapIconID (int) Table #2: properties id (int) IntID (int) What I want to accomplish is selecting all of the rows in properties, getting the MapIconID from the interiors table by using the IntID field. I'm not really good at explaining and it might sound confusing, so here's how it should work: * Select all the fields from properties * Find the `IntID` of each field and match it up with the corresponding id in the `interiors` table * Make a new column called `MapIconID` and display it Okay, I still think this sounds confusing - one more example. Example of `interiors`: Row 1: id:20, MapIconID:506 Row 2: id:21, MapIconID:149 Example of `properties`: Row 1: id:55, IntID:20 Row 2: id:56, IntID:0 What the result should be after selecting `properties` Row 1: id:55, IntID:20, MapIconID:506 Row 2: id:56, IntID:0, MapIconID:0 Hopefully someone can help me! Thank you kindly for your help. Quote Link to comment https://forums.phpfreaks.com/topic/187143-need-help-forming-a-select-query/ Share on other sites More sharing options...
ignace Posted January 4, 2010 Share Posted January 4, 2010 What you are looking for is called a join (http://dev.mysql.com/doc/refman/5.0/en/join.html) SELECT * FROM properties AS p JOIN interiors AS i ON p.IntID = i.id WHERE p.id = $pid Quote Link to comment https://forums.phpfreaks.com/topic/187143-need-help-forming-a-select-query/#findComment-988260 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.