Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am having the following two tables:

    dbo.Events

    EventID               EventName            Location
    1                     Birthday Party       2
    2                     Wedding              1

    dbo.EventsLocation

    Location    LocationName
    1           Room 1
    2           Room 2

I want to make an SQL query that returns the following:

    Birthday Party    Room 2
    Wedding           Room 1

2 Answers

0 votes
by (12.7k points)

You can use the following code for this, it will do the magic for you:

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

Want to get certified in SQL? Register for this complete SQL Course by Intellipaat. 

Watch this video tutorial on how to become a professional in SQL.

0 votes
by (1.5k points)

You can get the required result by joining two tables dbo.Events and dbo.EventsLocation using the Location ID as a basis for joining, using the following SQL query:

SELECT e.EventName, el.LocationName

FROM Events e

JOIN EventsLocation el ON e.Location = el.Location;

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...