mysql - How to delete duplicated rows with the same day? -
this question has answer here:
- deleting duplicates in mysql 4 answers
my table looks like:
id name value date 1 john 25 2013-03-23 16:42:35 2 john 25 2013-03-23 13:52:24 3 john 26 2013-03-22 03:12:43 4 gabriel 18 2013-03-23 10:21:07 5 rick 32 2013-03-21 04:37:29
how remove rows same name
, timestamp date
same day? example, table above should be:
id name value date 1 john 25 2013-03-23 16:42:35 3 john 26 2013-03-22 03:12:43 4 gabriel 18 2013-03-23 10:21:07 5 rick 32 2013-03-21 04:37:29
there many ways it. 1 using subquery gets 1 record of name in each day , result of subquery joined on table. non matching rows filtered , deleted.
delete tablename left join ( select name, date(date) dateonly, min(id) min_id tablename group name, date(date) ) b on a.name = b.name , date(a.date) = b.dateonly , a.id = b.min_id b.name null
Comments
Post a Comment