How to keep a record with the highest value

I want to keep only records with the highest value when a duplicate exists. The column containing the highest value is named Revision and the column containing the duplicate is named Manual_ID.

Ex:

     Manual_ID               Revision
  22.11.20_A1234               4
  22.11.20_A1234               5

I want to keep only the record containing Revision 5.
maximus1974Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
you can try:

select A.*
from YourTable as A
inner join (
   select manual_ID, max(revision) as Revision
   from YourTable 
   group by manual_ID
) AS B
on B.Manual_ID = A.Manual_ID
and B.Revision = A.Revision

Open in new window

0
JesterTooCommented:
If you want to delete the duplicates, then try this:

delete from tablname
 where revision not in
   (select max(revision) from tablname
     group by manual_id); 

Open in new window

0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
I think it can be as simplest as this if there's no other requirements:

select Manual_ID, Max(Revision) Revision
from yourTable
Group by Manual_ID

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.