In MySQL I have a table named contact_status :
id | id_contato | detalhamento_id
1 | 1 | 2
2 | 1 | 3
3 | 2 | 4
4 | 2 | 2
5 | 2 | 1
6 | 3 | 2
7 | 4 | 4
8 | 5 | 4
In it all the contact contacts of the site are recorded, and also whenever a status is modified (for history). What I need now is to list the total of the detail_id of each type. I got it with GROUP BY without problems. But it's not the right one. Because it also takes the duplicate entries (if a user has the modified status). So you would need to get only the detail_id of each user, but the last, with the largest ID. What I need to be shown is this:
detalhamento 1 - 1 ocorrência
detalhamento 2 - 1 ocorrência
detalhamento 3 - 1 ocorrência
detalhamento 4 - 2 ocorrência
How to do it?