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 p.`id_product` IN (
SELECT cp.`id_product`
' at line 5
SELECT COUNT(`id_product`) AS nb
FROM `ps_product` p
WHERE `active` = 1
AND DATEDIFF(p.`date_add`, DATE_SUB(NOW(), INTERVAL 40 DAY)) > 0
AND p.`id_product`!= AND p.`id_product` IN (
SELECT cp.`id_product`
FROM `ps_category_group` cg
LEFT JOIN `ps_category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` = 1
) LIMIT 1