List:General Discussion« Previous MessageNext Message »
From:LUCi5R Date:March 1 2012 3:30pm
Subject:RE: Getting data from 2 tables if records have same date!
View as plain text  
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:  luci5r@stripped
 w:  http://www.luci5r.com

-----Original Message-----
From: Halász Sándor [mailto:hsv@stripped] 
Sent: Wednesday, February 29, 2012 2:57 PM
To: mysql@stripped
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


Thread
Getting data from 2 tables if records have same date!LUCi5R29 Feb
  • Re: Getting data from 2 tables if records have same date!Johnny Withers29 Feb
    • RE: Getting data from 2 tables if records have same date!LUCi5R29 Feb
      • Re: Getting data from 2 tables if records have same date!Johnny Withers29 Feb
        • RE: Getting data from 2 tables if records have same date!LUCi5R1 Mar
      • Re: Getting data from 2 tables if records have same date!AndrĂ©s Tello1 Mar
      • Re: Getting data from 2 tables if records have same date!Shawn L Green1 Mar
        • Re: Getting data from 2 tables if records have same date!David Giragosian1 Mar
        • RE: Getting data from 2 tables if records have same date!LUCi5R1 Mar
          • Re: Getting data from 2 tables if records have same date!Shawn L Green1 Mar
    • Re: Getting data from 2 tables if records have same date!hsv1 Mar
      • RE: Getting data from 2 tables if records have same date!LUCi5R1 Mar