erme Posted September 13, 2013 Share Posted September 13, 2013 Hi, bit of a newbie question. I have a table called pages. I select all from this table. I need to also show the rows of another table called offers so the user can select an offer to display on this page. Question is, how do I select from both tables. pages table colums: ID Name Copy offers table columns:OffersID OffersTitle OffersDate OffersCopy OffersTypeOffersPrice I have tried variations of the below but does not work: SELECT * FROM pagesWHERE id = '" . $id . "'LEFT JOIN offers Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/ Share on other sites More sharing options...
requinix Posted September 13, 2013 Share Posted September 13, 2013 How are those two tables supposed to be related? Only term in common is the "copy" thing. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449407 Share on other sites More sharing options...
erme Posted September 16, 2013 Author Share Posted September 16, 2013 They arn't. I just want to pull data from both to display on the same page. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449648 Share on other sites More sharing options...
requinix Posted September 16, 2013 Share Posted September 16, 2013 There's no sense in trying to make one query to pull from both tables at the same time if they aren't related. Use two queries. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449652 Share on other sites More sharing options...
vinny42 Posted September 16, 2013 Share Posted September 16, 2013 There's no sense in trying to make one query to pull from both tables at the same time if they aren't related. And if the tables have different structures, like in this case, then it isn't even possible, SQL simply doesn't do that. SQL is set-based, each query returns one set of records, and what you (the OP) are trying to fetch here are two sets of data, so you should use two queries. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449654 Share on other sites More sharing options...
erme Posted September 17, 2013 Author Share Posted September 17, 2013 Okay thanks for your replies. Basically what I am trying to achieve is the ability for the user to be able to edit a page on a website (this bit I have done, using 'update pages') and select from a drop down box an offer that appears in the SQL table 'offers'. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449812 Share on other sites More sharing options...
vinny42 Posted September 17, 2013 Share Posted September 17, 2013 Then a separate query will be just fine. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449814 Share on other sites More sharing options...
erme Posted September 17, 2013 Author Share Posted September 17, 2013 Can you give me an idea of how I would do this. The offer can be used on as many pages throughout the site as the user wants. Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449831 Share on other sites More sharing options...
vinny42 Posted September 17, 2013 Share Posted September 17, 2013 Can you give me an idea of how I would do this. How to do what? Run a query? Quote Link to comment https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/#findComment-1449844 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.