Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to select two rows from a joined table

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading