MySQL delete data from a table

user4125170

I have timestamp value in a column of my table.I need to keep all the data of the last week and delete rest data in the table(which is not belong to last 7 days).How can I do it?

The query that I tried is given below.

DELETE * FROM EmailMainTable WHERE DATE_FORMAT(timestamp, '%Y-%m-%d %H:%i:%s') > 
DATE_SUB(DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%s'), INTERVAL 8 DAY);

NOTE: My Filed Name is timestamp and i converted it to bigint

My table's structure: enter image description here

Mureinik

Since you're converting the timestamps to varchars (using date_format), they will be compares lexicographically, which isn't the behavior you want. Just drop the formatting:

DELETE
FROM   EmailMainTable 
WHERE  `timestamp` > DATE_SUB(NOW(), INTERVAL 8 DAY);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

MySQL delete data from a table

From Dev

Delete data from a table by fetching data from another table in mysql

From Dev

How to delete mysql data from table at midnight?

From Dev

MySql delete from other table

From Dev

How to delete all data from MySQL table and populate table with new data

From Dev

Trigger to not delete Data from a table

From Dev

Data wont delete from table

From Dev

how to delete a single value from mysql table

From Dev

delete rows from a table using MySQL Scheduler

From Dev

delete from MySQL table after matching constraints

From Dev

Delete selected row from table in mysql

From Dev

Delete consecutive duplicates from a table in mysql

From Dev

Delete an entire row from a table, using MySQL

From Dev

delete from MySQL table after matching constraints

From Dev

Delete selected row from table in mysql

From Dev

mysql delete duplicate rows from table

From Dev

Delete from MySql table using aggregate functions?

From Dev

jQuery onclick delete row from mysql table

From Dev

mysql query help for delete entries from table

From Dev

How to delete millions of record from mysql table

From Dev

How do I SELECT data from a MySQL table and DELETE everything else?

From Dev

Mysql DELETE from table using information from another table

From Dev

Delete huge amounts of data from huge table

From Dev

Delete all data from table but not the columns

From Dev

delete a same data from multiple table in php

From Dev

Delete Data From Table of Specific Month

From Dev

delete existing row from data table

From Dev

copy and delete data from one table

From Dev

How to update and delete data from table?

Related Related

HotTag

Archive