Solved

Find Duplicates - SQL

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

     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 …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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…

830 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