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