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

  • Home
  • SEARCH
  • 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 6380843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:19:12+00:00 2026-05-25T02:19:12+00:00

Hi developers I am researching ways of fast selecting rows from many tables with

  • 0

Hi developers I am researching ways of fast selecting rows from many tables with identical structure. Tables have too much data to be 1 table. So every table contains data for 1 month.
For example log_2011_01 ,log_2011_02 etc. Tables have datetime column created_at.

I need to create stored procedure , it must contain 2 datetime parameters for searching between this dates and few others.

Now I see next realization:
stored procedure must calculate collection of tables between 2 dates and generate sql to select data with union_all .
I think I will be to heavy and not ready for highload,isn’t it?
Is there are any other possibilities to do this?
Thanks

  • 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-25T02:19:13+00:00Added an answer on May 25, 2026 at 2:19 am

    Agree with other comments, but I tried to help you with SP. This SP builds the query that can be executed with prepared statements.

    -- SP definition:
    
    DELIMITER $$
    
    CREATE PROCEDURE iterateMonths(IN fromDate DATE, IN toDate   DATE)
    BEGIN
      DECLARE tempDate DATE;
      DECLARE query    VARCHAR(1000); -- Query string, length might be increased
    
      SET tempDate = fromDate - INTERVAL (dayofmonth(fromDate) - 1) DAY;
    
      WHILE tempDate <= toDate
      DO
    
        IF query IS NOT NULL THEN
          SET query = concat(query, '\r\nUNION ALL\r\n');
        ELSE
          SET query = '';
        END IF;
    
        SET query = concat(query, 'SELECT * FROM log_', DATE_FORMAT(tempDate, '%Y_%m'));
        SET tempDate = tempDate + INTERVAL 1 MONTH;
      END WHILE;
    
      SELECT query; -- Output generated query
    END
    $$
    
    DELIMITER ;
    
    -- Call the SP
    
    SET @fromDate = '2010-07-29';
    SET @toDate = '2011-08-29';
    CALL iterateMonths(@fromDate, @toDate);
    
    -- Output:
    
    SELECT * FROM log_2010_07
    UNION ALL
    SELECT * FROM log_2010_08
    UNION ALL
    SELECT * FROM log_2010_09
    UNION ALL
    SELECT * FROM log_2010_10
    UNION ALL
    SELECT * FROM log_2010_11
    UNION ALL
    SELECT * FROM log_2010_12
    UNION ALL
    SELECT * FROM log_2011_01
    UNION ALL
    SELECT * FROM log_2011_02
    UNION ALL
    SELECT * FROM log_2011_03
    UNION ALL
    SELECT * FROM log_2011_04
    UNION ALL
    SELECT * FROM log_2011_05
    UNION ALL
    SELECT * FROM log_2011_06
    UNION ALL
    SELECT * FROM log_2011_07
    UNION ALL
    SELECT * FROM log_2011_08
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have noticed some developers picking up new skills and moving from one platform
Afternoon Developers, I have a problem that's beginning to get on my wick. I
Hello Ruby/Rails/Merb developers! Im currently working on a web project that will have a
Developers who have used eclipse cannot miss out the Cntrl+Shift+G combo - the easiest
Developers can use Apple’s iCloud APIs to sync app data between different versions of
I'm currently researching new source control options for a team of 10 developers. We
I'm researching a potential move from SourceSafe to Subversion and we are struggling with
Hopefully, someone here can give me some light. I have been researching this issue
I have spent the best part of a day researching and testing different methods
Developers have to 'opt in' for making classes serializable by explicitly using SerializableAttribute .

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.