SQL连接,获取具有相同名称的多个列 [英] SQL join, getting multiple columns with same name

查看:176
本文介绍了SQL连接,获取具有相同名称的多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表的列为IDSERVICE_TYPE_TEXT,而另一个表的列为

I have one table with a column ID and SERVICE_TYPE_TEXT, and another table with columns

ID, SERVICE_TYPE ... 

以及许多其他列.

第二个表中的SERVICE_TYPE包含第一个表中的ID.我想查询,以便从与第二张表中给出的ID相匹配的第一张表中获得SERVICE_TYPE_TEXT.

The SERVICE_TYPE in the second table contains the ID from the first table. I want to query so I can get the SERVICE_TYPE_TEXT from the first table that matches the ID given in the second table.

我尝试加入,并在IDAS上设置了不同的名称,但是总是在查询结果的末尾,我也从第一个表中以列名ID获得原始ID.作为我在AS中定义的名称.

I've tried to join, and setting different names on ID with AS, but always at the end of the query result I get the original ID from the first table with column name ID, as well as the name I defined in the AS.

关于如何从第一张桌子获得ID的任何建议要远离? :)

Any suggestions on how I can get the ID from the first table to stay away ? :)

推荐答案

尝试类似的方法

SELECT a.ID AS ServiceID,
       a.Service_Type_Text,
       b.ID AS table2ID,
       b.Service_Type
FROM   table1 a
       INNER JOIN table2 b
           ON a.ID = b.Service_Type

这篇关于SQL连接,获取具有相同名称的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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