I have two tables customers and orders, below is the structure.
Table - contacts
LEFT JOIN orders
ON contacts.id = orders.contact_id
GROUP BY contacts.id;
select the latest record in orders and group it first
select contacts.*, orders.id from contacts left join (select max(id) as id, contact_id from orders group by contact_id) orders on contacts.id = orders.contact_id