Skip to main content

HOW TO FIND DUPLICATE ROWS IN A TABLE (SQL)

If you are saddled with the task of finding duplicate rows in a table using SQL.

It is a simple task even though it is not a place you should find yourself because you need to make sure your records are well indexed at the time of creating your table. Now that the worst has happened. All you need do is to select the row that has the duplicate values and count for each of the rows using a GROUP BY clause. For convenience sake, you can order by the same column in question as shown below:

SELECT CurrentDate,
COUNT(*)
FROM
tblSingleRate
GROUP BY
CurrentDate
ORDER BY CurrentDate

CurrentDate Count(*)
2007-03-12 1
2007-03-13 2
2007-03-14 2
2007-03-15 1
2007-03-12 1
2007-03-13 1
2007-03-14 2
2007-03-15 1

Duplicates are marked in red.
QED!

Comments

Popular posts from this blog

Get Sum of Columns in a SharePoint list (Threshold edition)

It is a known fact that once the treshold limit is reached in SP, everything seems frozen.  At this point you have some options. Increase the limit using powershell or from the Central Admin OR Index the columns that you will like to operate on and create views based on those. However programmatically if you want to sum a list that has reached its threshold.  You can do so in batches as hown below:          protected   void  GetSummary( out   long  ideas,  out   long  votes,  out   long  comments,  out   long  transform)         {              long  ideasum = 0;              long columntoSum = 0;              long  commentS...

Add Web Visual Studio templates to SharePoint Project

Would you like to add the web user control to SharePoint 2007 project development.  Then open the project file with notepad and add {349c5851-65df-11da-9384-00065b846f21} to the ProjectTypeGUIDs node.   The necessary change is shown below: < ProjectTypeGuids > {349c5851-65df-11da-9384-00065b846f21};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} </ ProjectTypeGuids >