[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql
Subject:    Re: Getting data from 2 tables if records have same date!
From:       (Hal?sz S?ndor) hsv () tbbs ! net
Date:       2012-02-29 22:56:57
Message-ID: B0108267782 () mailhome ! tbbs ! net
[Download RAW message or body]

;>>> 2012/02/29 15:29 -0600, Johnny Withers >>>>
Sounds like you need to LEFT JOIN:

SELECT *
FROM CUSTOMERS
LEFT JOIN CALLS ON CUSTOMERS.PHONE = CALLS.PHONE AND CALLS.DATE = "02/28/12"
WHERE CUSTOMERS.DATE = "02/28/12"

But that would only get customers created on 2/28 AND having a call on 2/28
OR not call at all on 2/28.

This would give you customers created on 2/28 with no calls AND customers
created on 2/28 with a call on 2/28:

SELECT *
FROM CUSTOMERS
LEFT JOIN CALLS ON CUSTOMERS.PHONE = CALLS.PHONE
WHERE CUSTOMERS.DATE = "02/28/12" AND (CALLS.PHONE IS NULL OR CALLS.DATE =
"02/28/12")
<<<<<<<<
Exactly; but I believe that this is the right thing:

SELECT *
FROM CUSTOMERS LEFT JOIN CALLS USING(PHONE)
WHERE CUSTOMERS.DATE = "02/28/12" OR CALLS.DATE = "02/28/12"

If you have a hit --PHONE found in both tables--, you will get a record if either \
date matches, and I believe that you wanted that. If it is a miss --there is no \
CALLS-record for the PHONE-- CALLS.DATE will be NULL and not equal and only \
CUSTOMERS.DATE will match a date.

And if this works, surely it is clear where to put BETWEEN.


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/mysql


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic