I have the following MySQL query:
SELECT Project.*, `trk_deleted`, `trk_status`, `trk_state`
FROM `project` AS `Project` LEFT JOIN `trackline` ON `prj_id` = `trk_project`
WHERE `prj_deleted` = '0' GROUP BY `prj_id` ORDER BY `prj_name`;
This is a bit hard to explain, but basically, I have a structure in my database where Projects have multiple Tracklines. Both of these entities have fields prj_deleted and trk_deleted respectively which can have a 1 value if it was deleted (hidden from view), or a 0 value is it is not deleted (still in view).
My Project view page shows icons for each project based on the tracklines in that project. These icons are displayed based on the values of trk_status and trk_state
My Project view page should only show the project 1 time, even if it has multiple tracklines (hence the GROUP BY prj_id)
My Problem:
From the Mysql Documentation on GROUP BY:
“Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values the server chooses.”
My Project view page should ideally be displaying the icons for the tracklines that are not deleted. This is why I was hoping I could ORDER BY trk_deleted before the GROUP BY occurred so that grouping was done with a trackline that wasn’t deleted.
Hopefully someone can understand what I’m trying to get at here.
If you could provide some sample data and what you would like for the response, I could probably help with a better query. In the mean time: