Solved

Find Duplicates - SQL

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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 …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

776 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