开发者

Move record to different table MySQL

I see this question have been asked in many different ways, but I don't understand them quite well.

I want to move my records that have expired (their date is behind/smaller than now() - each one has a field with their date in, this is in seconds from 1970) to a different identical table. This is to make the event-cue smaller in th开发者_如何学Goe main table.

Is there any single query I can use to move a record to a different table? I can do the checking of the time/when expires myself.


You cant do this in one query, you have to perform two: query 1:

INSERT INTO newtable SELECT * FROM oldtable WHERE date<now();

query 2:

DELETE FROM oldtable WHERE date <= SELECT MAX(date) FROM newtable


insert into backupTable (select field1, field2 from mainTable where myDate < UNIX_TIMESTAMP(NOW()))

delete from mainTable where myDate < UNIX_TIMESTAMP(NOW())
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜