DEV Community

Timothy Soladoye
Timothy Soladoye

Posted on

1

List the data counted in mysql COUNT() GROUB BY GROUP_CONCAT()

We all know the regular group by and count

SELECT errors, COUNT(id) AS count AS ids 
FROM table GROUP BY errors;
Enter fullscreen mode Exit fullscreen mode

What if you want to see the ids that made up the count you have?
GROUP_CONCAT() will do that for you!

SELECT errors, COUNT(id) AS count, GROUP_CONCAT(id) AS ids 
FROM table GROUP BY errors;
Enter fullscreen mode Exit fullscreen mode
errors count ids
error1 4 2,3,4,5
error2 2 1,6
error3 1 8

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay