MySQL differences between to select queries

Posted by bpmccain on Stack Overflow See other posts from Stack Overflow or by bpmccain
Published on 2012-09-14T15:36:20Z Indexed on 2012/09/14 15:37 UTC
Read the original article Hit count: 508

Filed under:
|

I have two mysql queries that return a column of phone numbers. I want am trying to end up with a list of phone numbers that are in one list, but not in the other.

So the two queries I have are:

SELECT phone
FROM civicrm_phone phone
LEFT JOIN civicrm_participant participant ON phone.contact_id = participant.contact_id
WHERE phone.is_primary = 1
AND participant.id IS NULL

and

SELECT phone
FROM civicrm_phone phone
LEFT JOIN civicrm_participant participant ON phone.contact_id = participant.contact_id
WHERE phone.is_primary = 1
AND participant.id IS NOT NULL

And before anyone asks, the above two queries do not provide mutually exclusive results (based on using IS NULL and IS NOT NULL for the last WHERE statement), since we have related individuals in the database who use the same phone number, but do not necessarily all have a participant.id.

Thanks for any help.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about civicrm