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

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

ms access - C# - Using OleDbParameter on table name -