Remove partial duplicates from dataset

  • Thread starter Thread starter Gene.Averett
  • Start date Start date
G

Gene.Averett

I perform a query on a MySQL database and return a dataset.

the data looks like:

TaskID TaskName
201 Orca
205 Jaws
223 Orca
224 Orca

What I need from the dataset is the Orca with the larger TaskID and the
Jaws. So how do I remove the other 2 Orca with lower TaskID's?
 
select from <table> where TaskID in (select max(TaskID) from <table> where
TaskName='Orca') or TaskName<>'Orca'
 
You can construct your SQL statement like this:

SELECT TaskID, TaskName
FROM MyTable t1
WHERE TaskID = (SELECT MAX(TaskID) FROM MyTable t2
WHERE t2.TaskName = t1.TaskName)

Regards,

Plamen Ratchev
http://www.SQLStudio.com
 
Gene,

This has the name distinct. Tell what version you use than I can point you
to some documentation.

Cor
 
Back
Top