2012-01-04 79 views
9

我有2個表:是基於另一個表ID的查找返回值SQL查詢

dbo.Events 

    EventID    EventName   Location 
    1      Birthday Party  2 
    2      Wedding    1 

    dbo.EventsLocation 

    Location LocationName 
    1   Room 1 
    2   Room 2 

我想提出的是返回以下

Birthday Party Room 2 
    Wedding   Room 1 
+7

,因爲它看起來很像功課,第一個建議可能是谷歌爲「SQL連接」。 – 2012-01-04 23:40:52

回答

8
SELECT 
    Events.EventName AS EventName, 
    EventsLocation.LocationName AS LocationName 
FROM 
    Events 
    INNER JOIN EventsLocation ON Events.Location=EventsLocation.Location 
(WHERE ...) 
; 
0
Select e.eventname, l.locationname 
From events e 
Left join eventslocation l 
On e.location = l.location 
0
select 
     e.eventName, 
     el.locationName 
    from 
     Events e 
     join EventsLocation el 
      on e.location = el.location 
SQL查詢
0

加入表格:

select e.EventName, l.LocationName 
from Events e 
inner join EventsLocation l on l.Location = e.Location 
0
SELECT E.EventName,EL.LocationName 
FROM dbo.Events E 
INNER JOIN EventsLocation EL 
ON E.Location=EL.Location 
相關問題