user1131033
user1131033

Reputation: 133

SQL query that returns value based on lookup of id in another table

I have 2 tables:

    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

    Birthday Party    Room 2
    Wedding           Room 1

Upvotes: 13

Views: 78948

Answers (5)

Shyju
Shyju

Reputation: 218942

SELECT E.EventName,EL.LocationName 
FROM dbo.Events E 
INNER JOIN EventsLocation EL
ON E.Location=EL.Location

Upvotes: 0

Eugen Rieck
Eugen Rieck

Reputation: 65342

SELECT
  Events.EventName AS EventName,
  EventsLocation.LocationName AS LocationName
FROM
  Events
  INNER JOIN EventsLocation ON Events.Location=EventsLocation.Location
(WHERE ...)
;

Upvotes: 16

Guffa
Guffa

Reputation: 700850

Join the tables:

select e.EventName, l.LocationName
from Events e
inner join EventsLocation l on l.Location = e.Location

Upvotes: 2

DRapp
DRapp

Reputation: 48179

select 
      e.eventName,
      el.locationName
   from
      Events e
         join EventsLocation el
            on e.location = el.location

Upvotes: 0

user596075
user596075

Reputation:

Select e.eventname, l.locationname
From events e
Left join eventslocation l
On e.location = l.location

Upvotes: 0

Related Questions