SELECT course_courses.id FROM course_courses, course_courses_groups, course_courses_group_names WHERE (((UNIX_TIMESTAMP(start_date) >= AND (UNIX_TIMESTAMP(end_date)) <= ) OR (UNIX_TIMESTAMP(start_date) <= AND UNIX_TIMESTAMP(end_date) >= ) OR BETWEEN UNIX_TIMESTAMP(course_courses.start_date) AND UNIX_TIMESTAMP(course_courses.end_date) ) OR BETWEEN UNIX_TIMESTAMP(course_courses.start_date) AND UNIX_TIMESTAMP(course_courses.end_date)) AND (UNIX_TIMESTAMP(end_date) > 1500604206) AND course_courses.status = 1 AND course_courses.id = course_courses_groups.course_id AND course_courses_group_names.id = course_courses_groups.course_name_id ORDER BY course_courses.start_date DESC, course_courses.name ASC