Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Distinct
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

62 Posts

Posted - 09/26/2012 :  11:12:18  Show Profile  Reply with Quote
Can everyone tell me hwo to use for the query which has a lots of duplicate data.

For DISTINCT, I tried to use it, it works with the number and date, but it doesn't work when there is a filed of "note" or "text" or "description" with a long text.

Is there another way to check the DISTINCT data in a SQL query

Flowing Fount of Yak Knowledge

5155 Posts

Posted - 09/26/2012 :  11:39:49  Show Profile  Reply with Quote
Distinct operator eliminates a duplicate only if EVERY column in the select list are the same for two rows. So if the text or note column is different, the result would include both rows.

If there are different data in the note column of two otherwise identical rows, what rule do you want to determine which of those notes to pick up? Here is a way to pick one based on alphanumeric ordering.
;with cte as 
		ROW_NUMBER() OVER (PARTITION BY number,dat ORDER BY [description],[note]) AS RN

Edited by - sunitabeck on 09/26/2012 11:40:25
Go to Top of Page
  Previous Topic Topic Next 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.06 seconds. Powered By: Snitz Forums 2000