harryg
harryg

Reputation: 24077

Remove duplicates from MySQL table where 2 fields are the same

So I have a table with fields ID (AI, primary key), ticker, priceDate, price.

I have a bunch or records that share the same priceDate and ticker. There should only be one record per ticker for any given priceDate.

How would I go about removing these duplicate records, given that priceDate and ticker are not unique fields?

Upvotes: 0

Views: 133

Answers (1)

juergen d
juergen d

Reputation: 204746

delete from your_table
where id not in 
(
  select * from 
  (
    select min(id)
    from your_table
    group by pricedate, ticker
  ) x
)

Upvotes: 1

Related Questions