SELECT q.* FROM (
SELECT patient . * , visit.uid AS visit_uid
FROM patient
LEFT JOIN visit ON patient.uid = visit.patient_id
ORDER BY visit_uid DESC
) q GROUP BY q.uid ORDER BY q.visit_uid DESC
LIMIT 0 , 10
SELECT GROUP_CONCAT( table2.id ORDER BY table2.created_at DESC )
FROM table1 INNER JOIN table2 ON table1.id = table2.table1_id
GROUP BY
table1.id
ORDER BY
table2.created_at