In a query in MySql I need to select the results and sort the results based on how much they are repeated using the id_livro
column, for example:
My comments table:
+----------------+-------------+
| id_livro | comentario |
+----------------+-------------+
| 1 | Com1 |
+----------------+-------------+
| 1 | Com2 |
+----------------+-------------+
| 2 | Com3 |
+----------------+-------------+
| 3 | Com4 |
+----------------+-------------+
| 3 | Com5 |
+----------------+-------------+
| 3 | Com6 |
+----------------+-------------+
In this way I would like to organize a search that returns the most commented books in descending order from the most commented ones to the less commented ones that in the case would be book 3, 2 and 1
How would this query look? Ps: Results need to be grouped by book id as well.