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
https://forums.phpfreaks.com/topic/282134-selecting-from-2-tables/
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.

Archived

This topic is now archived and is closed to further replies.

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