Can someone help me to get all ids with the same color from this table? Thank you
Should return 1, 3, 9
Advertisement
Answer
You can try next query:
x
SELECT
p1.product_id p1
FROM `product_colors` p1
JOIN `product_colors` p2 ON p1.product_id <> p2.product_id AND p1.color_id = p2.color_id
GROUP BY p1.product_id, p2.product_id
HAVING COUNT(distinct p1.color_id) > 2
order by p1.product_id
;
Check it on SQLize.online