Jump to content

Better Way To Do This Simple Query?


CptnChainsaw

Recommended Posts

SELECT
   a.email
FROM a
LEFT JOIN b ON b.email=a.email
WHERE
  b.email IS NULL

 

That will join to table b matching up rows by the email field.  If no row exists in table b matching table a's email value, then all the fields in b will be NULL for that record.  The WHERE condition then filters the result to only the rows where the b.email field is null, meaning you only get the email's from a with no match in b.

 

Link to comment
Share on other sites

Hi,

 

If I wanted to join on another table would the query be something like this:

 

SELECT
  a.email
FROM a
LEFT JOIN b ON b.email=a.email
LEFT JOIN c ON c.email=a.email
WHERE
 b.email IS NULL AND c.email IS NULL

 

I tried this and its not quite right. I would only want to return records from table a if they are not in b and c.

 

Any further suggestions would be appreciated as always.

 

Thank you :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.