Tuesday, March 20, 2012

3 table query

I am trying to do something like this but keep getting a syntax error. How would I get something like this?

sql = "SELECT COUNT(optin) AS total_customers_optin FROM (SELECT tbl_customers.*, tbl_register.*, tbl_photos.* FROM tbl_customers, tbl_register, tbl_photos WHERE tbl_register.cust_id = tbl_customers.cust_id AND tbl_photos.photo_id = tbl_register.photo_id AND tbl_photos.photo_date = '04/26/2003' AND tbl_photos.event_id = '109' AND tbl_customers.optin = 'Yes' )">> I am trying to do something like this ...
>> How would I get something like this?

right now you appear to be counting photos

i can think of many queries that are "something like this"

what did you actually want? :)

rudy
http://rudy.ca/|||I am trying to count the number of distinct customers (using distinct email) who have selected Yes in the optin field and registered a photo from the event_id '109' and the photo_date is '04/26/2003'|||try this:SELECT count(DISTINCT tbl_customers.email)
FROM tbl_customers
, tbl_register
, tbl_photos
WHERE tbl_register.cust_id
= tbl_customers.cust_id
AND tbl_photos.photo_id
= tbl_register.photo_id
AND tbl_photos.photo_date = '04/26/2003'
AND tbl_photos.event_id = '109'
AND tbl_customers.optin = 'Yes'rudy|||Thats it!

Thanks for your help.

No comments:

Post a Comment