在表中合并三个表 [英] merge three table in on table
问题描述
我有三个桌子
1)SysSettings 2)SysSettingsDep 3)SysSettingsMachine
现在,我们要根据以下条件合并此表:
1)通过"SettingKey"列将它们合并到一个名为"SysSettingsCustomer"的表中
2)合并它们时,我有一列"TableName"以显示"settingKey"哪个表是您的
我想要这样的结果:
SysSettingKey _ TableName
------------------------------
CompanyName _ SysSettingDep
希望您能理解我的问题,所以请帮助我.
tnx
_Amir
Hi,
I have three table
1) SysSettings 2) SysSettingsDep 3) SysSettingsMachine
now, we want to merge this table according the following condition-:
1) merge them to one table that''s name "SysSettingsCustomer" by column "SettingKey"
2) when merge them i have a column "TableName" to show "settingKey" Which table is yours
I want the result like this:
SysSettingKey _ TableName
------------------------------
CompanyName _ SysSettingDep
I hope you understand my problem so, please help me.
tnx
_Amir
推荐答案
如果我以正确的方式理解您的问题,我认为以下解决方案可能会有用.
If I understand your question in a right way, I think the following solution could be useful.
select B.SettingKey SettingKey, 'SysSettingsDep' AS TableName
from dbo.SysSettings A
inner join dbo.SysSettingsDep B on A.SettingKey = B.SettingKey
union
select C.SettingKey SettingKey, 'SysSettingsMachine' AS TableName
from dbo.SysSettings A
inner join dbo.SysSettingsMachine C on A.SettingKey = C.SettingKey
这篇关于在表中合并三个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!