Results tagged “Databases” from aaronlongwell.com

Xaprb is a great resource for SQL tricks, especially MySQL tricks. Here's an explanation of some techniques to delete duplicate rows with a grouped self-join. I needed this in order to add a unique index to a table.

[select/delete] bad_rows.*
from test as bad_rows
   inner join (
      select day, MIN(id) as min_id
      from test
      group by day
      having count(*) > 1
   ) as good_rows on good_rows.day = bad_rows.day
      and good_rows.min_id <> bad_rows.id;
tagged with: Databases MySQL SQL

Who's this guy?

Aaron Longwell is Chief Web Craftsman at New Media Logic Corporation in Coeur d' Alene, Idaho. As a professional software developer for 12 years and a student of public policy, he occasionally has interesting things to say about software, technology, culture and politics.

Subscribe to feed Subscribe to my RSS Feed