Solved

SQL - no duplicate row of combination of ColumnA and ColumnB

Posted on 2010-09-08
2
570 Views
Last Modified: 2012-05-10
This query is for quality check on a TableAB- query checks that there is no duplicate row with the same values of ColumnA and ColumnB.
Example:
ColumnA                    ColumnB              ColumnC             ColumnD
2                                   6                     22                   23
2                                   6                     26                    42

This case above should not happen. The query needs to return such records if they exist.
0
Comment
Question by:spirose
2 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 33632109
SELECT ab.ColumnA, ab.ColumnB, ab.ColumnC, ab.ColumnD
FROM TableAB ab INNER JOIN
    (SELECT ab2.ColumnA, ab2.ColumnB
    FROM TableAB ab2
    GROUP BY ab2.ColumnA, ab2.ColumnB
    HAVING COUNT(1) > 1) AS z ON ab.ColumnA = z.ColumnA AND ab.ColumnB = z.ColumnB
ORDER BY ab.ColumnA, ab.ColumnB, ab.ColumnC, ab.ColumnD
0
 

Author Comment

by:spirose
ID: 33632426
Works great- thank you.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL replication over high latency link 10 59
Database ERD 4 28
SQL Log size 3 17
.NET Enums [Flags] & Bitwise Design Question 6 26
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

856 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