SELECT translationId FROM products where lang=:lang AND translationId IN (SELECT affi.pid
FROM all_filters_filters_items affi
WHERE affi.fid IN (14395,14427)
GROUP BY affi.pid
HAVING SUM(CASE WHEN affi.fid IN (14395) THEN 1 ELSE 0 END) > 0 AND SUM(CASE WHEN affi.fid IN (14427) THEN 1 ELSE 0 END) > 0) and translationId in (select distinct pid from products_categories where cid in (-1,323)) and active=1