So i have two tables with information below one which is a holiday table which marks the location to and from and etc. and another table that has the information on the locations
holiday_id | location_from | location_to | start_time | end_time |
---|---|---|---|---|
1 | 21 | 43 | 13:00 | 17:00 |
Location_id | location_name |
---|---|
21 | sydney |
43 | gold coast |
I’d like to have an sql query which will return the names of the location to and from but because location name is under one column im not sure how to do it. any help is appreciated
>Solution :
You can join with the table, twice, using an alias:
select location_1.location_name, location_2.location_name, other, columns
from holidays
join locations location_1 on holidays.location_from = location_1.location_id
join locations location_2 on holidays.location_to = location_2.location_id