Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 770363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:29:18+00:00 2026-05-14T18:29:18+00:00

I’m looking for the function that will take rows older then X days and

  • 0

I’m looking for the function that will take rows older then X days and put it in archive table…
Was thinking to make function so it will be easer to execute… something like

CREATE TABLE archive_NUMBER_OF_WEEK (...);
INSERT INTO archive_NUMBER_OF_WEEK SELECT * FROM content WHERE DATE < X days;
DELETE * FROM content WHERE DATE < X days

Will post if I manage to write it by myself 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:29:18+00:00Added an answer on May 14, 2026 at 6:29 pm

    Ok, I finality wrote it 🙂
    It took me a while but here it is:

    DELIMITER $$
    
    DROP PROCEDURE IF EXISTS `procedure`.`rotate_events_pro`$$
    CREATE DEFINER=`confiq`@`%` PROCEDURE `rotate_events_pro`(p_threshold_rotate_row int,p_days_to_keep int,OUT p_message VARCHAR(200))
    BEGIN
        DECLARE v_id_to_move INT;
        #lets take ID that we need to move
        #we can't use variables in LIMIT, how smart MySQL!
        SET @v_sql = CONCAT('SELECT max(id) 
            INTO @v_id_to_move
            FROM events
            WHERE event_created < DATE_ADD(CURDATE(), INTERVAL - ',p_days_to_keep,' DAY) OR 
            id < (SELECT min(id) FROM (SELECT id FROM events ORDER BY id DESC LIMIT ?) as id)');
        PREPARE stmt1 FROM @v_sql;
        SET @param1 = p_threshold_rotate_row;
        EXECUTE stmt1 USING @param1;
            DEALLOCATE PREPARE stmt1;
        #we have IDs that need to to be moved to arhive
        IF @v_id_to_move > 0 THEN
            START TRANSACTION;
                INSERT INTO archived_events SELECT * FROM events WHERE id < @v_id_to_move;
                INSERT INTO archived_eventsinfo SELECT * FROM eventsinfo WHERE event_id < @v_id_to_move;
                DELETE FROM events WHERE id < @v_id_to_move;
                DELETE FROM eventsinfo WHERE event_id < @v_id_to_move;
            COMMIT;
            SET p_message = CONCAT('moved all events that id is < ',@v_id_to_move);
        ELSE
            SET p_message = 'Nothing to move';
        END IF;
    END$$
    
    DELIMITER ;
    

    Feel free to feedback or edit it for your own use 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 382k
  • Answers 382k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If ".div2" is inside ".div1", you could use position:relative on… May 14, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer public void setPartner(Partner b) { // Special case, otherwise we'll… May 14, 2026 at 10:30 pm
  • Editorial Team
    Editorial Team added an answer Have you got a namespace clash, is myEmployer a class… May 14, 2026 at 10:30 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.