I have a table called contacts , where all contacts made on the site are registered. There is also a table named status , where the service status of each contact is stored.
In doubt, I need to SELECT contacts, and in LEFT JOIN only show the last status recorded in the status table. I did this:
SELECT * FROM contato
LEFT JOIN status ON status.id_contato = contato.id
GROUP BY status.id_contato
ORDER BY contato.dia DESC
The problem with this query is that with GROUP BY it ends up showing only the first status, not the last one. How to group and then show the last one (with the longest and most current ID)?