I have some duplicate records in a table I would like to remove but keep the minimum ID record in the table as the unique record.
The query to return the minimum ID records I want to keep is as follows:
select
MIN(ID) AS ID
, Date
, Portfolio
, Instrument
, Dimension
, COUNT(ID)
from mytable
group by date, Portfolio, Instrument, Dimension
having COUNT(ID) > 1
order by date, Portfolio, Instrument, Dimension
However i'm unser as to how to write the query to ensure that I delete all the duplicates except the MIN(ID) records above. I'm guessing it is going to have to be a sub query against all the IDs that are duplicates except the above?