Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL - no duplicate row of combination of ColumnA and ColumnB

Posted on 2010-09-08
2
Medium Priority
?
580 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 93

Accepted Solution

by:
Patrick Matthews earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

618 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