Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to take Diffrence of sets?

Status
Not open for further replies.

sqltimmy

Programmer
May 29, 2002
7
US
I have a query with one column and 937 rows.
I have another query with the same one column and 595 rows.
I want to query the difference of these queries, but I am having a heck of a time finding the syntax to do it! I'm using SQL Server 2000 and it's not liking the DIFFERENCE function...

Example SQL:

SELECT ID
FROM TABLE1

[insert magic function here!]

SELECT ID
FROM TABLE2

 
Hi,

I think this should give u the results u want

SELECT ID
FROM TABLE1 where ID Not IN(
SELECT ID
FROM TABLE2)

Sunil
 
Here are two other options. They should prove more efficient than a NOT IN query.

Not Exists:

Select ID
From table1
Where not exists
(Select * From table2 Where ID=table1.ID)

Left Join:

Select ID
From table1
Left Join Table2
On table1.ID=table2.ID
Where table2.ID Is Null Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top