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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:44:56+00:00 2026-06-13T11:44:56+00:00

I need to build a table from several tables in MySql and I want

  • 0

I need to build a table from several tables in MySql and I want it has two columns like:

-------------------
name | table_name |
-------------------

I’m doing this:

Create table teams as 
(
Select name from table1
union
Select name from table2
union
Select name from table3);

How could I include each table name as a second column??

Thank you!

  • 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-13T11:44:57+00:00Added an answer on June 13, 2026 at 11:44 am

    Include a quoted string literal. Be sure to also give it a column alias, which will be used as the column name in the resultant table.

    CREATE TABLE teams AS 
      /* Quoted string literal with column alias */
      (SELECT name, 'table1' AS `tablename` FROM table1)
      UNION 
      (SELECT name, 'table2' AS `tablename` FROM table2)
      UNION
      (SELECT name, 'table3' AS `tablename` FROM table3);
    

    Note that since you are in effect adding a second value to each row which differentiates it from potentially similar rows in the other tables, the UNION is now the eqivalent of a UNION ALL, and duplicate rows won’t be de-duped as the plan UNION would have. Just beware, that the results may differ from what your original UNION produced.

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

Sidebar

Related Questions

Hi I need to build a table with two columns from a mySQL table.
I would need to build a html table that has a horizontally scrollable column.
I need to build an SQL statement to delete from certain table the records
I have a need to build a string from Last Name, First Name, Middle
I need to build a class that will represent a row in some table
I need to build a feature like most of the banks use. Where.. if
I need to build a multidimensional array from records retrieved from my database. Here
I have a need to build a schema structure to support table of contents
I would like to output the following table from my database DateTime | Measure
I have the next two tables: CREATE TABLE #SalesByStore ( Brand VARCHAR(10), StoreName VARCHAR(50),

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.