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 '-100, 50' at line 5. SELECT DISTINCT(p.id), p.*, g.img FROM (products p, product_categories pc) LEFT JOIN gallery g ON g.u_id = p.id && type_id = '0' && g.main = '1' WHERE pc.p_id = p.id && pc.c_id IN (353, 396, 355, 360, 359, 398, 357, 356, 358, 354, 387, 125) ORDER BY p.active DESC, added desc LIMIT -100, 50