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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:15:24+00:00 2026-06-04T12:15:24+00:00

Possible Duplicate: How can I merge two MySql tables? I want to merge multiple

  • 0

Possible Duplicate:
How can I merge two MySql tables?

I want to merge multiple tables that have the same structure and make one large table. The tables have similar names, so I want to use the LIKE statement. Can anyone tell me how I can do this?

The tables are very simple, each having an ID column and a few other columns, but there are a large amount of tables, all of which have names like 'TX-xxx', where 'TX' means Texas, and 'xxx' are the counties in Texas; you know there are more than 200 counties in Texas. (In fact, I have to do this for all the states.) So I want to use the statement "LIKE 'TX-___'".

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-06-04T12:15:26+00:00Added an answer on June 4, 2026 at 12:15 pm

    You would have to give more information so we know exactly what you want but you could create a view

    CREATE VIEW myViewName AS 
    
    select * 
    from table1 
    
    union all 
    
    select * from 
    table2 
    

    This way it would show the information from all your tables (and can be limited so in the selects to not show everything) and when table1, table2, etc are changed the view will reflect this. You can change it at anytime and fetch from it as you would a table:

     select * from myViewName
    

    Now for grabbing from specific tables I am not sure how you can do this in mysql though I have done it in tsql. This previous question would help you so you might have something like:

    -- Create temporary table of varchar(200) to store the name of the tables. Depending on how you want to go through the array maybe an id number (int). 
    insert into tempTableName (name)
    SELECT table_name FROM information_schema.tables WHERE table_schema = 'database_name' and table_name like 'TX_%';
    declare @sqlQuery varchar(max)
    --Then you will want to loop through the array and build up an sql statement
    -- For each loop through:
         if len(@sqlQuery) = 0 begin -- first time through
             set @sqlQuery = 'select col1, col2, col3 from ' + currentTableName
         end else begin -- second+ time through
             set @sqlQuery = 'union all select col1, col2, col3 from ' + currentTableName
         end
    -- after the loop add the create view. Could double check it worked by checking length = 0 again
    set @sqlQuery = 'CREATE VIEW myViewName AS ' + @sqlQuery
    Once the query string is built up you will execute it with
    PREPARE stmt FROM @sqlQuery;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: How can I merge properties of two JavaScript objects dynamically? I have
Possible Duplicate: Merge two lists in python? How can I prepend list elements into
Possible Duplicate: Merge 2 Arrays and Sum the Values (Numeric Keys) I have two
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
I have several huge sorted enumerable sequences that I want to merge . Theses
Possible Duplicate: Can i save lots of bitmaps to one bitmap? (2d) I wonder
Possible Duplicate: How can I merge 3 images into 1 image via PHP? How
I have two somewhat big (4+ million records) tables with identical structure, and they
Possible Duplicate: Can't pass mysqli connection in session in php Many of us have
Possible Duplicate: Can I set a breakpoint on 'memory access' in GDB? I want

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.