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)
 In table A, not in table B

Author  Topic 

pug2694328
Posting Yak Master

166 Posts

Posted - 2006-08-21 : 15:47:27
Are there any other ways to pull rows where a unique key is on a row in table A , but not in a row in table B? Here is how I know how to do it, but am wondering if there are any other ways. Thanks in advance!

-- Way 1
SELECT *
FROM TABLE_A A
WHERE
NOT EXISTS (
SELECT NULL
FROM TABLE_B B
WHERE A.KEY = B.KEY
)

SELECT
*
FROM TABLE_A A
LEFT JOIN
TABLE_B B
ON A.KEY = B.KEY
WHERE
B.KEY IS NULL

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-08-21 : 16:02:17
May be this is more inefficient

-- Way 3
SELECT *
FROM TABLE_A A
WHERE
A.Key Not in (
SELECT B.KEY
FROM TABLE_B B
)


Srinika
Go to Top of Page
   

- Advertisement -