SQL Server Select Query to Find Duplicates within a file

Posted on 2014-08-12
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
Question by:hojohappy
    LVL 25

    Accepted Solution

    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.
    LVL 1

    Expert Comment

    Select Product_Code,ProductSource
    from Products
    Group By Product_Code,ProductSource
    Having Count(*) > 1
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    In this article—a derivative of my blog post (—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
    Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now