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 2008 Forums
 Transact-SQL (2008)
 Difference between SQL statements
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

itmasterw
Yak Posting Veteran

90 Posts

Posted - 03/27/2013 :  09:36:54  Show Profile  Reply with Quote
Hi,
Both of these check for duplicate rows but what is the difference between them?

select distinct source_file, claimNo, memberid, count(*)
from dbo.Claims_Header_2013
group by source_file, claimNo, memberid
having count(*)>1

select distinct source_file
from dbo.Claims_Header_2013
group by source_file, claimNo, memberid
having count(*)>1

thank you

ITM

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 03/27/2013 :  09:42:17  Show Profile  Reply with Quote
This is the main logic..... ( logic for checking duplicate combination of source_file, claimNo, memberid)

group by source_file, claimNo, memberid
having count(*)>1

If you need the source_file, claimNo, memberid, count(*) cnt in the display, then consider first query; Otherwise use second query
Go to Top of Page

itmasterw
Yak Posting Veteran

90 Posts

Posted - 03/27/2013 :  10:25:17  Show Profile  Reply with Quote
Thank you that made it clearer

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