Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Qwery for rcds excluding in another table?

Author  Topic 

sbt1
Yak Posting Veteran

89 Posts

Posted - 2004-01-22 : 11:43:01
Let's say I have a table "Employees" and another "Groups".

I want to open a recordset using a query which will return the 'LastName' field for each record in "Employees" where the 'LastName' value does NOT exist in the 'Name' field of any records in the "Groups" table.

In other words, I want all the last names of the employees who don't appear in the 'Name' field any of the records of the Groups table.

Any idea how to do this?

raymondpeacock
Constraint Violating Yak Guru

367 Posts

Posted - 2004-01-22 : 11:47:06
Try

SELECT LastName
FROM Employees
WHERE LastName NOT IN (SELECT Name FROM Groups)


Raymond
Go to Top of Page
   

- Advertisement -