wemustdesign Posted July 20, 2011 Share Posted July 20, 2011 I have 3 tables for my website, Locations, Attractions and Location_Attractions (stores which attractions can be found at the different locations) I am Locations id name 1 Las Vegas Attractions id name 1 Casino 2 Hotel Location_Attractions location_id attraction_id 1 1 1 2 trying to get my head round how I perform a query to show which locations a certain attraction can be found at. For example on the Casino page I am going to list oll of the locations this can be found at. So I know I need to query Location_Attractions to find all of the locations that have the correct attraction_id (eg 1 for Casino). I then need to link this to the Locations table to retrieve the details about the locations (such as name, address). Any idea how I would do this, would I use a JOIN? Quote Link to comment https://forums.phpfreaks.com/topic/242477-query-question/ Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 since the number of fields are the same in each table, you can actually use a Union here Quote Link to comment https://forums.phpfreaks.com/topic/242477-query-question/#findComment-1245357 Share on other sites More sharing options...
DavidAM Posted July 20, 2011 Share Posted July 20, 2011 This is no place for a UNION. This requires a 3-table JOIN, which AbraCadaver posted for you in your original topic: http://www.phpfreaks.com/forums/index.php?topic=339140.msg1598717#msg1598717 Quote Link to comment https://forums.phpfreaks.com/topic/242477-query-question/#findComment-1245358 Share on other sites More sharing options...
AyKay47 Posted July 20, 2011 Share Posted July 20, 2011 it depends on how the OP wants the data displayed, perhaps I am misunderstanding the goal here Quote Link to comment https://forums.phpfreaks.com/topic/242477-query-question/#findComment-1245359 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.