I want to combine/union two tables and have it create a field that identifies which table it came from

大城市里の小女人 提交于 2020-01-21 18:50:29

问题


I want to combine/union two tables and have it create a field that identifies which table it came from. I saw an answer for SQL but I do not need max values. I just need to Union two tables. Here is my current SQL for a union query I made through access' query.

SELECT [TableA].[1As], [TableA].[2As]
UNION
SELECT [TableB].[1As], [TableA].[2As];

I want the tables to create whichtabl field and populate whatever word I tell it based on the the table it came from to look like this:


Fields:    1As       2As    WhichTabl
data: 100 1 TableA 110 0 TableB

thanks in advanced! Please excuse me I am a newbie!


回答1:


You can just add in the column as a constant:

SELECT "TableA" as which, [TableA].[1As], [TableA].[2As]
FROM TableA
UNION ALL
SELECT "TableB", [TableB].[1As], [TableB].[2As]
FROM TableB


来源:https://stackoverflow.com/questions/23437026/i-want-to-combine-union-two-tables-and-have-it-create-a-field-that-identifies-wh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!