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 'and folder_id = f.id and account_id = a.id and a.status_id = 2 group by f.id ord' at line 2