Avatar of maximus1974
maximus1974
 asked on

Need help eliminating duplicates and keeping the last record

Need a SQL statement that eliminates duplicates and chooses the last record entered.

Ex. WO1002421 has two entries. I want to keep the record of the last person Wilmer Tamayo-Sanchez.

This statement below is what I am using but as unfortunately, it still brings in duplicates.  
SELECT MAX(WO_NUMBER) as wo_number
	  ,FIRST_NAME
      ,LAST_NAME
  FROM BA_VIEW_WO_LABOR
WHERE SKILL NOT LIKE '%INSPECTOR'
GROUP BY WO_NUMBER
      ,FIRST_NAME
      ,LAST_NAME
	  having count(*)>1
ORDER BY WO_NUMBER 

Open in new window

Capture.JPG
Oracle Database* PL/SQLSQL

Avatar of undefined
Last Comment
johnsone

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Sean Stuber

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
johnsone

How do you define "last one"?  Typically, there is a date field or something like that to order by to determine which one is first or last.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23