Jump to content

Simple I bet but I still need a bit of guidance...


ToonMariner

Recommended Posts

HI peeps...

 

I have a table of journeys  storing the id of starting location and end location.

 

I would like one query that would return both location names as specified (i.e. start and end)

 

Something like...


SELECT
`location`.`name` AS `start` ,
`location`.`name` AS `end`
FROM
`journeys`
LEFT JOIN
`journeys`
ON
`journeys`.`start_id` = `location`.`location_id`
LEFT JOIN
`journeys`
ON
`journeys`.`end_id` = `location`.`location_id`
WHERE
`journey_id` = SPECIFIED_ID

 

any tips much appreciated

 

Heres one way to do it.

 

select location_s.start as start, location_e.name as end

from journeys, location as location_s, location as location_e

where journeys.start_id = location_s.location_id

and journeys.end_id = location_e.location_id

and journeys.journey_id = ?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.