Solved

Find Duplicates - SQL

Posted on 2013-01-03
3
325 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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

11 Experts available now in Live!

Get 1:1 Help Now