Skip to content

Instantly share code, notes, and snippets.

@pereirawe
Last active December 7, 2019 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pereirawe/1fc54a94234d25945edb97be72725c38 to your computer and use it in GitHub Desktop.
Save pereirawe/1fc54a94234d25945edb97be72725c38 to your computer and use it in GitHub Desktop.
Move rows from a table to another from a date
SET @START = 10, @finish = 3;
INSERT INTO old_log
SELECT
*
FROM
log
WHERE
time >= DATE(NOW() - INTERVAL @start MONTH )
AND
time <= DATE(NOW() - INTERVAL @finish MONTH );
DELETE FROM
log
WHERE
time >= DATE(NOW() - INTERVAL @start MONTH )
AND
time <= DATE(NOW() - INTERVAL @finish MONTH );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment