Jump to content

List of records in table A without corresponding record in table B


Recommended Posts

Hey all,

I'd like to create a list of records in one table that do not have a corresponding (join?) record in another table.

I have one table called 'members' that has a MemberID field.

A second table called 'listings' holds records that are joined by MemberID.

Is there an "easy" way to get a list of records in the 'members' table that DO NOT have a corresponding record in the 'listings' table?

Thanks for any help...
Subqueries can be slow. You will probably find that this executes much faster

[code]$ql = "SELECT m.* FROM members m
     LEFT JOIN listings l ON m.MemberID = l.MemberID
     WHERE l.MemberID IS NULL";[/code]
Thanks for the advice Barand...but your version does not give any results. (The other version produces verifiably true results.)

However, another problem:

"My" version of the query works fine on my local host, but when I upload it to a hosting server it produces an error:

[code]
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'select distinct MemberID from pppx_listings)' at line 1
[/code]

Very strange. Any insights?
MySQL versions 4.1+ support subqueries.

LEFT JOIN available in all versions.

Check table and column names in my code - it's a traditional tried and tested means of finding unmatched records
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.