首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何获取表名并将其追加到查询中?

如何获取表名并将其追加到查询中?
EN

Stack Overflow用户
提问于 2014-05-14 07:06:38
回答 1查看 66关注 0票数 0

我在一个access数据库上工作,其中有多个具有相似数据的表。除了确定每个记录来自哪个表之外,我还想查询相似的字段。

这就是到目前为止我所拥有的,我有多个联合来附加在多个表上相同的字段,但是我遇到麻烦的部分是添加标识表名的列。

请帮帮我!非常感谢!

代码语言:javascript
运行
复制
SELECT DISTINCT SAP_charger.[Object type] FROM SAP_charger 
UNION
SELECT DISTINCT SAP_DME.[Object type] FROM SAP_DME
UNION 
SELECT DISTINCT SAP_fiber_optic_repeater.[Object type] FROM SAP_fiber_optic_repeater
UNION
SELECT DISTINCT SAP_gateway.[Object type] FROM SAP_gateway 
UNION
SELECT DISTINCT SAP_HMI.[Object type] FROM SAP_HMI 
UNION
SELECT DISTINCT SAP_managed_switch.[Object type] FROM SAP_managed_switch
UNION 
SELECT DISTINCT SAP_media_converter.[Object type] FROM SAP_media_converter
UNION
SELECT DISTINCT SAP_meter.[Object type] FROM SAP_meter 
UNION
SELECT DISTINCT SAP_OLM.[Object type] FROM SAP_OLM 
UNION
SELECT DISTINCT SAP_PLC.[Object type] FROM SAP_PLC 
UNION
SELECT DISTINCT SAP_relay.[Object type] FROM SAP_relay 
UNION
SELECT DISTINCT SAP_satellite_clock.[Object type] FROM SAP_satellite_clock 
UNION
SELECT DISTINCT SAP_terminal_server.[Object type] FROM SAP_terminal_server 
INNER JOIN
SELECT MSysObjects.Name AS table_name
FROM MSysObjects 
WHERE table_name in ( 'SAP_charger', 'SAP_DME', 'SAP_fiber_optic_repeater', 'SAP_gateway', ' SAP_HMI', 'SAP_managed_switch', 'SAP_media_converter', 'SAP_meter', 'SAP_OLM', 'SAP_PLC', 'SAP_relay', 'SAP_satellite_clock', 'SAP_terminal_server')
;
EN

回答 1

Stack Overflow用户

发布于 2014-05-14 07:09:36

像这样怎么样?

代码语言:javascript
运行
复制
SELECT DISTINCT SAP_charger.[Object type],'SAP_charger' FROM SAP_charger 
UNION
SELECT DISTINCT SAP_DME.[Object type],'SAP_DME' FROM SAP_DME
..... 
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23643052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档