问题
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