I have a table where I need to check or compare two rows, two columns are equal, but only I need to get the data
my table structure
id | route_id | stop_id | bus_id | bus_time | trip | direction
if I execute the following query
select routes.route_name,stops.stop_name,buses.bus_name,bus_timings.bus_time,bus_timings.trip,bus_timings.bus_direction from `bus_timings`
inner join `stop_orders` on `stop_orders`.`id` = `bus_timings`.`stop_order_id`
inner join `routes` on `stop_orders`.`route_id` = `routes`.`id`
inner join `stops` on `stop_orders`.`stop_id` = `stops`.`id`
inner join `buses` on `buses`.`id` = `bus_timings`.`bus_id`
where `stops`.`stop_name` in ("sydney","melborne")
Output
1 | route_1 | Sydney | bus_1 | 07:05 :00 | 1 |1
2 | route_1 | Melbourne| bus_2 | 07:35:00 |1 |1
but in the existing query, even if the bus does not travel between Sydney, I will also get the result of Melbourne, I need to get only the name of the buses that falls or travels between Sydney and Melbourne.
source
share