SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 In table A, not in table B
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pug2694328
Posting Yak Master

166 Posts

Posted - 08/21/2006 :  15:47:27  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

Sri Lanka
1378 Posts

Posted - 08/21/2006 :  16:02:17  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000