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 stt,id desc' at line 1syntax error: SELECT COUNT(*) as `num` FROM table_baiviet where hienthi=1 and type='tai-lieu-hoc' and id_cat= order by stt,id desc