Solved

SQL - no duplicate row of combination of ColumnA and ColumnB

Posted on 2010-09-08
2
567 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

810 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