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 ' ) UNION ALL SELECT t2.categoryId as categoryId, t2.sort_order as sort_order,' at line 3