Results 1 to 5 of 5

Thread: 3 table query

  1. #1
    Join Date
    Oct 2002
    Location
    Houston, TX
    Posts
    34

    Unanswered: 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' )"

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    >> 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/

  3. #3
    Join Date
    Oct 2002
    Location
    Houston, TX
    Posts
    34
    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'

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    try this:
    Code:
    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

  5. #5
    Join Date
    Oct 2002
    Location
    Houston, TX
    Posts
    34
    Thats it!

    Thanks for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •