Solved

SQL - no duplicate row of combination of ColumnA and ColumnB

Posted on 2010-09-08
2
574 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

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?
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

717 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