[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Server Select Query to Find Duplicates within a file

Posted on 2014-08-12
3
Medium Priority
?
208 Views
Last Modified: 2014-08-24
Need a SQL Select query that will find duplicates within the same file on multiple columns.  Table is called Products.  
Two columns; Product_Code and Product_Source.    Need to find all records that have multiple occurances of Product_Code + Product_Source.

For example;

Product_Code       Product_Source
12345                    A
12345                    A                       ---> Duplicate
18888                    A
18888                    C                       ---> Not a duplicate record
44000                    D
99999                    C
99999                    C                     ---> Duplicate
0
Comment
Question by:hojohappy
3 Comments
 
LVL 25

Accepted Solution

by:
Luis Pérez earned 2000 total points
ID: 40255787
Try this:

SELECT CAST(Product_Code AS VARCHAR) + Product_Source, COUNT(*)
FROM Products
GROUP BY CAST(Product_Code AS VARCHAR) + Product_Source
HAVING COUNT(*) > 1

Open in new window

Hope that helps.
0
 
LVL 1

Expert Comment

by:Dukster131
ID: 40255798
Select Product_Code,ProductSource
from Products
Group By Product_Code,ProductSource
Having Count(*) > 1
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have a large data set and a SSIS package. How can I load this file in multi threading?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question