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 'ASC ORDER BY p.sort ASC, ASC' at line 6SQL: SELECT pi.path FROM post AS p LEFT JOIN post_image AS pi ON ( pi.post_id = ) WHERE p.category_id = 84 AND p.sort = 0 GROUP BY ASC ORDER BY p.sort ASC, ASC