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!
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.
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
UNIONis now the eqivalent of aUNION ALL, and duplicate rows won’t be de-duped as the planUNIONwould have. Just beware, that the results may differ from what your originalUNIONproduced.