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