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
 General SQL Server Forums
 New to SQL Server Programming
 set difference?

Author  Topic 

intergalacticplanetary
Starting Member

12 Posts

Posted - 2007-02-06 : 16:11:43
hi, i'm having difficulty figuring out how to implement a set difference between two queries. the only set operator i've been able to come across is union. thanks in advance!
d

sshelper
Posting Yak Master

216 Posts

Posted - 2007-02-06 : 16:13:49
To be able to do a set difference, you can either use the NOT EXISTS, NOT IN, or LEFT OUTER JOIN. For more information about these options, you can refer to question #3 in the following link:

http://www.sql-server-helper.com/faq/select-p01.aspx

SQL Server Helper
http://www.sql-server-helper.com
Go to Top of Page

intergalacticplanetary
Starting Member

12 Posts

Posted - 2007-02-06 : 16:28:39
quote:
Originally posted by sshelper

To be able to do a set difference, you can either use the NOT EXISTS, NOT IN, or LEFT OUTER JOIN.


hi, i'm familiar with those operators but am not sure how to use them with multiple columns. for example, i have two tables with the same 2 columns and i want to return only those rows in table 1 that are not also in table 2. i've been doing this:

SELECT column_1, column_2
FROM table_1
WHERE column_1 NOT IN (SELECT column_1 FROM table_2)
AND column_2 NOT IN (SELECT column_2 FROM table_2);

...however, as expected, this doesn't return the proper results. it performs independent checks on the column values where i'm looking to remove rows that have the same unique column_1, column_2 combination.

Go to Top of Page

intergalacticplanetary
Starting Member

12 Posts

Posted - 2007-02-06 : 16:35:51
got it figured out...thanks anyway!
Go to Top of Page
   

- Advertisement -