SELECT lessons.id AS lid, join_lessons_status.status_id AS sid FROM lessons INNER JOIN join_lessons_status ON join_lessons_status.lesson_id = lessons.id INNER JOIN join_lessons_indicator_types ON join_lessons_indicator_types.lesson_id = lessons.id WHERE active = 'true' AND indicator_id = 1 GROUP BY lid, sid ORDER BY join_lessons_status.timestamp DESC, sid DESC, lid DESC