SQL Query Error (SELECT distinct s.*, r.ref_category, r.ref_subject FROM subjects s, subjects_relations r WHERE LENGTH(s.name) > 0 and r.ref_subject = s.id AND r.ref_category= order by s.name) : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by s.name' at line 3