could anyone help me build up a query based on the query bellow.
As you can see I have a product with specifications and certain groups which are build up in the front-end. I know the problem, 1 column can’t be 2 values at once but I need only those products that are in those 2 groups.
To illustrate, product_specification_sid, id 2 3 and 4 are sizes and de rest 8 ~ 11 are colors, so I would like to select a product that has 2 and 3.
Inner joining the table double isn’t an option since the groups (sizes, colors) may vary in the future.
SELECT
products.*,
categories.*,
manufacturers.*
FROM products
INNER JOIN product_categories ON product_category_pid = product_id
INNER JOIN categories ON product_category_cid = category_id
INNER JOIN manufacturers ON product_manufacturer = manufacturer_id
INNER JOIN product_specifications ON product_specification_pid=product_id
WHERE
product_active = 1
AND
(
product_specification_sid in (3)
AND
product_specification_sid in (8,9,6,7,10,11)
)
GROUP BY product_id
You can use a having clause instead.