Solved

Find Duplicates - SQL

Posted on 2013-01-03
3
323 Views
Last Modified: 2013-01-03
I am looking to find all the duplicates in our database based on duplicate upc code only if the uom = 'CA' or 'UOM' and not null.

part_code	uom	upc_code
PUR14192	CA	017800141888   
PUR14192	EA	017800141888
PUR14192	LB	NULL
PUR14192	PL	NULL
1428	        CA	052742142814
1428	        EA	052742142807
1428	        LA	NULL
1428	        LB	NULL
1428	        PL	NULL

Open in new window


So it would show as the output.

part_code	uom	upc_code
PUR14192	CA	017800141888   
PUR14192	EA	017800141888

Open in new window



Any help would be greatly appreciated.
0
Comment
Question by:gpsdh
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 38741097
Something like (air code, so replace the obvious stuff)...

SELECT yt.*
FROM YourTable yt
JOIN  (
    SELECT upc_code, Count(upc_code) as the_count
    FROM YourTable
    WHERE uom = "CA" or "EA"
    GROUP BY upc_code
    HAVING COUNT(upc_code) > 1 ) c ON yt.upc_code = c.upc_code
0
 

Author Closing Comment

by:gpsdh
ID: 38741141
Thanks!
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38741161
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

760 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

21 Experts available now in Live!

Get 1:1 Help Now