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 9215013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:06:22+00:00 2026-06-18T02:06:22+00:00

I am working on a mysql query for a report. The idea is to

  • 0

I am working on a mysql query for a report. The idea is to have a simple table say ‘reportTable’ with the values being fetched from various places. I could then use the reportTable more easily without remembering lots of joins etc and also share this table for other projects.

  1. Should I break down the inner insert part of the query so it does
    chunks at a time I will be adding probably tens of thousands of rows?

INSERT INTO reportTable
(
   -- long query grabbing results from various places
   SELECT var1 FROM schema1.table1
   SELECT var2 FROM schema2.table1
   SELECT var2 FROM schema2.table1
   etc
)
  • 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-06-18T02:06:23+00:00Added an answer on June 18, 2026 at 2:06 am

    This addresses your concerns that inserting data takes too long and so on. I understood it like you rebuild your table each time. So, instead of doing so, just fetch the data that is new and not already in your table. Since looking up if the data is already present in your report table might be expensive, too, just get the delta. Here’s how:

    Make sure that in every table you need a column like this is present:

    ALTER TABLE yourTable ADD COLUMN created timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP;
    

    The ON UPDATE clause is of course optionally, don’t know if you need to keep track of changes. If so, give me a comment and I can provide you with a solution with which you can keep a history of your data.

    Now you need a small table that holds some meta information.

    CREATE TABLE deltameta (tablename varchar(50), LSET timestamp, CET timestamp);
    

    LSET is short for Last Successful Extraction Time, CET for Current Extraction Time.

    When you get your data it works like this:

    UPDATE deltameta SET CET = CURRENT_TIMESTAMP WHERE tablename = 'theTableFromWhichYouGetData';
    SELECT @varLSET := LSET, @varCET := CET FROM deltameta WHERE tablename = 'theTableFromWhichYouGetData';
    INSERT INTO yourReportTable (
        SELECT whatever FROM aTable WHERE created >= @varLSET AND created < @varCET
    );
    UPDATE deltameta SET LSET = CET WHERE tablename = 'theTableFromWhichYouGetData';
    

    When anything goes wrong during inserting your script stops and you get the same data the next time you run it. Additionally you can work with transactions here, if you need to roll back. Again, write a comment if you need help with this.

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

Sidebar

Related Questions

I have a working mysql query that retrieves data from table1. Now I will
Any idea why the following code is not working mysql credentials are correct, have
I have the following mysql query working well. Quick backstory, this lists our customers
I have this mysql query using PHP and first part is working fine, but
I have this working MySQL query (it's stripped down to show only relevant lines):
I built working MySQL query: SELECT v.*, u.username FROM video AS v, users AS
I have the following, working MySQL query: SELECT a.id id, a.price price, a.stock stock,
I am working with mysql and php and have a Parent Child table created
I'm trying to export a mysql query table to an excel file. I have
I am working on a simple search interface in a MyISAM table in MySQL,

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.