选择UNION ALL以将表名显示为附加列(Select with UNION ALL to display tablename as an additional column)
mysql
对于MSSQL或MySQL,这是一个将两个结果合二为一的查询:
SELECT boy as person from table1 union all SELECT girl as person from table2如何修改上面的查询,以便结果包含带有表名的第二个(添加的)列(因此它包含table1或table2值)。
For MSSQL or MySQL, here is a query that unites two results into one:
SELECT boy as person from table1 union all SELECT girl as person from table2How to modify the query above so that the result contains the second (added) column with the name of the table (so it contains table1 or table2 value).
最满意答案
你可以给表格名称作为第二列的字符串横向
SELECT boy as person, 'table1' as column2 from table1 union all SELECT girl as person, 'table2' as column2 from table2you can give string lateral with table name as second column
SELECT boy as person, 'table1' as column2 from table1 union all SELECT girl as person, 'table2' as column2 from table2更多推荐
发布评论