Jump to content

SELECT statement with DISTINCT, but with fields from two tables...


mac007

Recommended Posts

Hi, all:

 

I have this statement:

 

"SELECT DISTINCT offer_email, email_subject, email_body FROM email_blast, customer_emails_copy WHERE id = $itemid"

 

I have two tables, and the "offer-email" belongs to the customer_emails_copy one. I also want to select the other fields from second table normally (not DISTINCT), is this the right way? I dont seem to be getting what I expect...

 

Thanks for your help!

Wrong forum to post this in.

 

Your SQL says offer_email. Is it offer_email or offer-email? As far as I know, DISTINCT works across all columns you select. Which column do you want distinct? Be careful if both table has an ID field. You may want to specify which id gets used in your WHERE clause. Same for those columns you select.

 

I would write this:

SELECT offer_email, email_subject, email_body
FROM email_blast, customer_emails_copy
WHERE id = '$itemid'
GROUP BY offer_email

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.