I hope someone can help.
Hi am building a transit app for Android and I have hit a snag.
I would like to get all of the busses/routes which service a particular stop.
e.g. Stop No: 12345 have Busses: 123 & 321.
I have this piece of SQL:
SELECT DISTINCT rt.route_short_name
FROM routes rt
LEFT JOIN trips tr
ON rt.route_id = tr.route_id
LEFT JOIN stop_times st
ON tr.trip_id = st.trip_id
WHERE st.stop_id = 12345
But the query takes a long time per stop.
I have indexes on:
routes (route_id)
stops (stop_id)
trips (trip_id, service_id, route_id)
stop_times (trip_id, stop_id)
Apart from doubling the size of my SQLite database, it hasn't done a great deal for the speed.
Does anyone know of a faster way to retrieve the values I require at a reasonable speen on an android device?
Thanks in advance.
This sorted it for those who are interested. It has gone from 7 seconds per query to less than a second for 10 queries.
select distinct rt.route_short_name
from routes rt, trips tr, stop_times st
where rt.route_id = tr.route_id
and tr.trip_id = st.trip_id
and st.stop_id =
Regards
R