so i have a table that looks like the following
tool_id | tool_user
hammer adam
hammer adam
hammer sandra
screwdriver sandra
So i am trying to select the tools ordered by number of usages (record occurrences) and also concat all the users in a field, the tricky part is to count and sort the users by number of occurences as well
So far, i was able to get the tools by usages and order them but i am not sure how to sort the users by number of occurrences.
The expected result of the select statment is:
tool users
hammer adam,sandra
screwdriver sandra
Current the SQL statement looks like following:
SELECT tool_id, GROUP_CONCAT(tool_user SEPARATOR ",") AS tool_users, COUNT(*) AS count FROM tools_table GROUP BY tool_id ORDER BY count DESC LIMIT 5