mysql, select and sorting by group key + with first row that has that key in another column
0
votes
1
answer
269
views
I'm trying to make a select that outputs everything, but is sorted by a group column with a "header column" that matches said group column on another column.
I have no idea how this type of query should be written. For example, I want the data sorted like this.
id, unit, group, col2, col3, col4, col5
---------------------------------------------
99, ZZX, null, test1, test7, test5, test
6, AAA-B, ZZZ, test1, test7, test5, test8
77, AAA-C, ZZX, test1, test7, test5, test9
101, ZZZ, null, test1, test7, test5, test
122, AAB-A, ZZZ, test1, test7, test5, test11
176, AAB-B, ZZZ, test1, test7, test5, test12
So basically, the unit should be sorted per each group key, but begins with the row that matches the group key. There are also rows with null for group, but are just header rows. You can even just tell me the high level, and I can write the query, I'm just not sure the best way to approach it.
Asked by J. M. Becker
(129 rep)
Feb 25, 2020, 06:00 PM
Last activity: May 19, 2025, 09:07 PM
Last activity: May 19, 2025, 09:07 PM