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

^^^ This is going into an endless loop; I'm not getting any result at all.
I'm not sure why. I haven't used USING before so I need to read up a bit on
that to understand what you're doing here. 

Thanks!

 ~~
 LUCi5R
 e:  luc...@luci5r.com
 w:  http://www.luci5r.com

-----Original Message-----
From: Halász Sándor [mailto:h...@tbbs.net] 
Sent: Wednesday, February 29, 2012 2:57 PM
To: mysql@lists.mysql.com
Subject: Re: Getting data from 2 tables if records have same date!

;>>> 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



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

Reply via email to