Jump to content

Selecting from 2 tables


erme

Recommended Posts

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                
OffersType
OffersPrice            
 

I have tried variations of the below but does not work:

 

SELECT * FROM pages
WHERE id = '" . $id . "'
LEFT JOIN offers

 

 

Link to comment
Share on other sites

 


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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.