基于在另一个表中查找 id 返回值的 SQL 查询
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8735676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 13:50:39 来源:igfitidea点击:
SQL query that returns value based on lookup of id in another table
提问by user1131033
I have 2 tables:
我有2张桌子:
dbo.Events
EventID EventName Location
1 Birthday Party 2
2 Wedding 1
dbo.EventsLocation
Location LocationName
1 Room 1
2 Room 2
I would like to make an SQL query that returns the following
我想做一个返回以下内容的 SQL 查询
Birthday Party Room 2
Wedding Room 1
回答by Eugen Rieck
SELECT
Events.EventName AS EventName,
EventsLocation.LocationName AS LocationName
FROM
Events
INNER JOIN EventsLocation ON Events.Location=EventsLocation.Location
(WHERE ...)
;
回答by Guffa
Join the tables:
加入表:
select e.EventName, l.LocationName
from Events e
inner join EventsLocation l on l.Location = e.Location
回答by Guffa
Select e.eventname, l.locationname
From events e
Left join eventslocation l
On e.location = l.location
回答by DRapp
select
e.eventName,
el.locationName
from
Events e
join EventsLocation el
on e.location = el.location
回答by Shyju
SELECT E.EventName,EL.LocationName
FROM dbo.Events E
INNER JOIN EventsLocation EL
ON E.Location=EL.Location