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 'index) ORDER BY p.active DESC, added desc' at line 4. 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 (79, 292, 64, 228, 55, 371, 243, 452, 62, 142, 389, 325, 262, 460, 488, 412, 454, 2, 3, 10, 158, 12, 13, 290, 15, 16, 17, 407, 176, 18, 159, 19, 20, 21, 317, 22, 38, 283, 23, 24, 280, 25, 379, 140, 26, 28, 293, 162, 29, 195, 30, 32, 33, 34, 35, 178, 36, 37, 272, 252, 39, 40, 41, 42, 401, 294, 43, 334, 45, 160, 46, 139, 179, 468, 473, 347, 346, 483, 5, 386, 343, 344, 222, 268, 277, 4, 297, 310, 309, 313, 312, 299, 326, 321, 303, 302, 304, 307, 301, 300, 308, 305, 392, 306, 311, 322, 298, 319, 315, 314, 318, 316, 251, 459, 403, 476, 485, 381, 402, 497, 414, 399, 446, 48, 495, 493, 499, 498, 49, 390, 461, 348, 477, 175, 413, 479, 463, 486, 50, 487, 467, 471, 475, 6, 165, 226, 345, 341, 397, 51, 8, 56, 60, 242, 57, 52, 494, 365, 141, 53, 214, 58, 411, 61, 63, 406, 496, 67, 163, 54, 415, 66, 68, 69, 328, 229, 480, 342, 474, 271, 363, 278, 388, 465, 78, 442, 73, 351, 74, 374, 75, 462, 417, 76, 470, 77, 373, 481, 444, 261, 295, 296, 256, index) ORDER BY p.active DESC, added desc