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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:50:32+00:00 2026-05-26T03:50:32+00:00

We have MYSQL table of MERGE Storage Engine which merges data from 40 tables

  • 0

We have MYSQL table of MERGE Storage Engine which merges data from 40 tables (“table01” through “table40“). Once we run a SELECT query we get all the entries from all the merged MySQL tables. The structure and behaviour of MERGE table is as expected.

However it happens that we need to identify which merged table row entry came from or corresponds to which merged table, i.e.

  • rowA => “table01“
  • rowB => “table12“
  • rowC => “table12“
  • rowD => “table35“
  • rowE => “table39“
  • row… => “table…“

Is there a way to do this with MySQL MERGE storage engine?

  • 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-26T03:50:32+00:00Added an answer on May 26, 2026 at 3:50 am

    Not that elegant but you could add an identifying integer column on each of your tables, specify that column with a default value of 1 ,2 (depending on which table it is – you could even chuck in a lookup table (tableId –> tableName) and then you should be able to tell from which table a given row came.

    You’d have to make the same changes to the MERGE table too of course…

    Lovingly ripped off the MERGE MySQL docs:

    CREATE TABLE t1 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,message CHAR(20)) ENGINE=MyISAM;
    
    CREATE TABLE t2 (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY,message CHAR(20)) ENGINE=MyISAM;
    
    INSERT INTO t1 (message) VALUES ('Testing'),('table'),('t1');
    INSERT INTO t2 (message) VALUES ('Testing'),('table'),('t2');
    
    CREATE TABLE total (a INT NOT NULL AUTO_INCREMENT,message CHAR(20),INDEX(a)) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;
    
    alter table t1 add column identifier int unsigned not null default 1;
    alter table t2 add column identifier int unsigned not null default 2;
    
    drop table total;
    
    CREATE TABLE total (a INT NOT NULL AUTO_INCREMENT,message CHAR(20),identifier int unsigned,INDEX(a)) ENGINE=MERGE UNION=(t1,t2) INSERT_METHOD=LAST;
    

    You will have the rather dull task of altering all 40 tables though…

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

Sidebar

Related Questions

MySQL docs say that tables that use the MERGE storage engine can only union
I have two mysql tables and i want to merge the results of these
How can I merge two MySQL tables that have the same structure? The primary
I am setting up a table in mysql of engine type merge in mysql
I'm attempting to merge data from one MySQL database into another. The problem is,
I would like merge 2 MySQL tables without adding the same lines. I have
I have mysql table that has a column that stores xml as a string.
I have a MySQL table with approximately 3000 rows per user. One of the
I have a MySQL table containing domain names: +----+---------------+ | id | domain |
I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION

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.