问题描述
我有一个表的列为ID
和SERVICE_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.
我尝试加入,并在ID
和AS
上设置了不同的名称,但是总是在查询结果的末尾,我也从第一个表中以列名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连接,获取具有相同名称的多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!