php - Need Mysql Query for Search Bus from stop and To Stop -


i create table buses , route , stop tables

buses table

id ,  bus_name  1      aaa  2      bbb 

stop table

id, stop_name, latitude, longitude  1    xyz        12.5555    77.222  2    sss        13.5555    77.2888  3    eee        88.444     77.222  4    c          34.8859309  -97.47070  5    jjj        32.9902355   -97.99804 

route table

id, bus_id,  stop_id, arrival_time,   departure_time,     start_end_stop   1      1        1         0000            8.00am        start   2      1        2        8.10am          8.10am    3      1        3        8.15am          8.16am   4      1        4        8.20am          8.20am    5      1        5        8.25am          0000            end   6      2        1        0000            8.10am          start   7      2        3        8.15am          8.18am   8      2        5        8.27am           0000           end 

now search stop xyz jjj

i want result is

bus_name  from_stop_name  departure_time  to_stop_name  arrival_time  notes   aaa       xyz             8.00am             jjj            8.25am   nil   bbb       xyz             8.10am             jjj            8.27am   nil 

or search stop xyz c

bus_name  from_stop_name   departure_time  to_stop_name arrival_time  notes   aaa       xyz             8.00am             c         8.20am        nil   bbb       xyz             8.10am             jjj       8.27am        jjj c 600 mts 

i need mysql selecting query , please me.

i think query below give desired results. better parameterize inputs make query more general.

select buses.bus_name, s1.stop_name from_stop_name, t1.departure_time,  s2.stop_name to_stop_name, t2.arrival_time buses inner join table t1 on t1.bus_id = buses.id inner join stop s1 on s1.id = t1.stop_id inner join table t2 on t2.bud_id = buses.id inner join stop s2 on s2.id = t2.stop_id buses.bus_name in ('aaa', 'bbb') , s1.stop_name = 'xyz' , s2.stop_name = 'jjj' 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -