SELECT *
FROM table1 t1
LEFT JOIN
table2
ON o.id =
(
SELECT o_id
FROM table2 t2
WHERE t2.c_id = t1.c_id
ORDER BY
t2.c_id DESC, t2.isHeadOffice DESC, t2.o_id DESC
LIMIT 1
)
Crea un indice su table2 (c_id, isHeadOffice, o_id) affinché funzioni velocemente.
Il ORDER BY La clausola nella sottoquery può sembrare ridondante ma è richiesta per MySQL per scegliere l'indice giusto.