Data:
id  uid     type
1   20      A
2   20      B
3   20      A
4   6       A
5   1       A
6   3       A
7   6       A
8   1       B
Scenario:
I want to group by type and sort it by id. I am using group by to group the uid.
Current Query:
SELECT
    type,
    GROUP_CONCAT(DISTINCT uid) AS users,
    COUNT(type) AS typeCount
FROM
    `test2`
GROUP BY
    type
Problem:
But the order of the uid is incorrect, it should be in descending order according to id.
Expected Result:
type    users       typeCount
A       6,3,1,20    6
B       1,20        2
My results:
type    users       typeCount
A       20,6,1,3    6
B       20,1        2
 
     
     
     
     
     
     
    