June 11, 2004 at 10:34 am
Hi,
I am trying to select a set of records from one table that do not appear in a second table.
ie. Client Contacts have owners. The owners are held in a seperate table containing just the Contact ID and the owner ID. I need to run a report on all Contacts without an owner.
Bet it's easy but I'm a newbie. Any help appreciated
June 11, 2004 at 11:07 am
There are a number of ways to do this. My personal choice is using a LEFT JOIN and check for NULL condition.
SELECT
*
FROM
Clients C
LEFT JOIN
Owners O
ON
C.ContactID = O.ContactID
WHERE
O.ContactID IS NULL
June 11, 2004 at 11:09 am
This would do it. It runs a select for those contactids in the clientcontacts table that are not in the select of the contactids that have a matching contactid in the owners table.
SELECT ContactID
FROM ClientContacts
WHERE ContactID NOT IN (SELECT ContactID
FROM ClientContacts C
INNER JOIN Owners O
ON C.ContactID = O.ContactID)
June 11, 2004 at 1:21 pm
Thanks everyone. I'll try these out on Monday. Knew it would be easy for the "Old Pro's"
June 11, 2004 at 1:32 pm
Less of the "old" thankyou...
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply