First of all, here’s the query I will talk about :
SELECT route_id, direction_id
FROM stop_times
LEFT JOIN trips USING (trip_id)
WHERE stop_id= 1002
GROUP BY CONCAT(route_id, direction_id)
Example of the expected results :
route_id | direction_id
-----------------------------
106 | 0
106 | 1
13 | 0
13 | 1
21 | 0
4 | 0
4 | 1
6 | 0
So, running this query will take an averge of 0.088 second. This is ok… But if I remove the GROUP BY it take 0.0026 second.
Now my question is :
Will it be better to do the GROUP BY and handle everything in MySQL or fetch everything and handle it in an array in PHP ?
Thanks
You can replace this:
by this:
You will have the same results in much less time.