我想合并/合并两个表,并让它创建一个字段来标识它来自哪个表 [英] I want to combine/union two tables and have it create a field that identifies which table it came from

查看:71
本文介绍了我想合并/合并两个表,并让它创建一个字段来标识它来自哪个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想合并/合并两个表,并让它创建一个字段来标识它来自哪个表.我看到了SQL的答案,但我不需要最大值.我只需要合并两个表.这是我当前通过访问查询进行的联合查询的SQL.

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.

选择[TableA].[1As],[TableA].[2As]
UNION
选择[TableB].[1As],[TableA].[2As];

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

我希望这些表创建whichtabl字段,并根据它来自的表来填充我告诉它的任何单词,如下所示:

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!

推荐答案

您可以将列作为常量添加:

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

这篇关于我想合并/合并两个表,并让它创建一个字段来标识它来自哪个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆