sql - How do I delete records in MySQL and keep the lastest date -



sql - How do I delete records in MySQL and keep the lastest date -

example table_1

id email reply updatedate 1 xxx.@xx.com 1 2011-07-02 2 xxx.@xx.com 3 2011-07-11 3 vvv.@xx.com 3 2011-07-12 4 vvv.@xx.com 5 2011-07-13 5 xxx.@xx.com 5 2011-07-14 6 xxx.@xx.com 4 2011-07-14 7 xxx.@xx.com 4 2011-07-14 8 zzz.@xx.com 4 2011-07-15

how delete records maintain latest updatedate

and result :

id email reply updatedate 4 vvv.@xx.com 5 2011-07-13 7 xxx.@xx.com 4 2011-07-14 8 zzz.@xx.com 4 2011-07-15

you utilize temporary variable store highest date , seperate query delete < that. remember variables connection specific.

select max(updatedate) table_1 @tempupdatedate delete table_1 updatedate < @tempupdatedate

mysql sql

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -