合并来自不同SQL查询的两个或更多列 [英] Merging two or more columns from different SQL queries

查看:266
本文介绍了合并来自不同SQL查询的两个或更多列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难弄清楚如何将两列与sql合并(我是新手).它应该真的很简单,但是我根本找不到方法.我从两个不同的select语句中得到了两个结果,它们都具有相同的行数,但是具有不同的列.我只想将所有列附加"在一起.

I'm having a hard time figuring out how to merge together two columns with sql (I'm new at it). It should be really simple but I simply can't find a way to do it. I have two results from two different selects statements, and they both have the same number of rows, but different columns. I just want to "attach" all the columns together.

示例. 这是第一个表:

Example. This is the first table:

这是第二张表:

以下查询:

SELECT [t].* FROM [TrainerClass] AS [t];

或者简单地

SELECT * FROM [TrainerClass];

将给出显示在这里的结果:

will give the result shown here:

现在,第二个查询是:

SELECT [d].[Description] AS [Name] FROM [DescriptionTranslation] AS [d], [TrainerClass] AS [t] WHERE [d].[TableName] = 'TrainerClass' AND [d].[FieldName] = 'Name' AND [d].[Code] = [t].[Code] AND [d].[Language] = 'en-EN';

将在此表中显示

挺直的.现在,我只是想得到的是这样:

Pretty straight forward. Now, what I simply want to get is this:

为什么我这么难?您将如何实现这一目标?预先感谢!

Why is it so hard to me? What would you do to achieve that? Thanks in advance!

推荐答案

SELECT [t].*,
       [d].[Description] AS [Name],
       [d2].[Description] AS [Description]
FROM   [TrainerClass] AS [t] join [DescriptionTranslation] AS [d] on [t].[Code] = [d].[Code]
       join [DescriptionTranslation] AS [d2] on [t].[Code] = [d2].[Code]
WHERE  [d].[TableName] = 'TrainerClass' AND 
       [d].[FieldName] = 'Name' AND 
       [d].[Language] = 'en-EN' AND
       [d2].[FieldName] = 'Description'

这篇关于合并来自不同SQL查询的两个或更多列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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