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
 General SQL Server Forums
 New to SQL Server Programming
 topic 1
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

deeptish
Starting Member

India
1 Posts

Posted - 06/05/2012 :  07:47:39  Show Profile  Reply with Quote
Can somebody help me by writing a query that retrieve the unique combination of records (value1,value2) those are present in query 1 but not in query 2.

NOTE : table 2 is much bigger than table 1 and both the table may have duplicate values

Query 1

Select value1,value2 from <table 1>
group by value1,value2
order by value1,value2

Query 2

Select value1,value2 from <table 2>
group by value1,value2
order by value1,value2


Thanks
Deeptish

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 06/05/2012 :  09:32:11  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
Select distinct t1.value1,t1.value2
from [table 1] t1
left join [table 2] t2
on t1.value1 = t2.value1
and t1.value2 = t2.value2
where t2.value1 is null




==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47099 Posts

Posted - 06/05/2012 :  10:24:33  Show Profile  Reply with Quote

Select value1,value2 from <table 1> t1
WHERE NOT EXISTS (SELECT 1 FROM <table 2>
                  WHERE value1 = t1.value1 
                  AND value2 = t1.value2
                  )


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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.05 seconds. Powered By: Snitz Forums 2000