MySQL Forums
Forum List  »  MySQL Query Browser

How to get list of stations between two
Posted by: Jatin Soni
Date: December 19, 2019 02:54AM

How to list all station between selected two stations based on `next_station_id`

For instance, if the user selects origin A station and destination to J than I want to list all stations in ORDER that have set into the `next_station_id` column.

I have an intermediate level of knowledge in MySQL and have no idea how to write such a query.

SELECT r.number as route, s.name AS station, s.code AS station_code, rl.name AS line, s.line_two_id AS interchange
FROM stations AS s
JOIN route_stations as rs
ON rs.station_id = s.id
JOIN routes r
ON rs.route_id = r.id
JOIN route_lines rl
ON s.line_id = rl.id
ORDER BY rs.station_order ASC;

> I know the above query is just to join table but as I said I have no
> clue how to write a query to get a list of stations that have been set
> in `next_station_id`

#route_stations table
[![enter image description here][1]][1]

I am also adding a diagram in case anyone wants to look the structure to refer and suggest

#Diagram

Options: ReplyQuote


Subject
Written By
Posted
How to get list of stations between two
December 19, 2019 02:54AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.