select h.*, from_unixtime(h.time_date) as sdano, m.members_display_name as student_name
from (select h.id, h.student_id, h.mark, h.passed_time as time_date, s.teacher_id, h.comments, s.subject_name, l.lesson_name
from homeworks h, subjects s, lessons l
where h.checked_time between 1535922000 and 1540933200
and h.checked=1
and l.subject_id=s.id
and h.lesson_id=l.lesson_id
and s.display=1
select a.id, a.student_id, a.mark, a.request_time as time_date, a.teacher_id, a.comment as comments, 'Административные баллы' as subject_name, m.full_name as lesson_name
from administrative_balls a, members m
where m.id=a.teacher_id
and a.submit_time between 1535922000 and 1540933200
and a.status=2) h, ibf_members m
where h.student_id=m.id
and h.=
order by h.subject_name, h.time_date - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '= order by h.subject_name, h.time_date' at line 16