'MySQL Filter for at least 1 of 3 values in a column
I'm trying to learn SQL and I have got this table with the following columns:
purchase_ID: Integer
department_name: Shoes, Shirts, Trousers
item: blue shoes, red shoes, green shoes, blue trousers, red trousers, green trousers, blue shirt, red shirt, green shirt,
How do I filter for IDs that bought at least 1 pair of shoes, 1 pair of trousers and 1 pair of shirt TOGETHER? Here is my code:
SELECT
purchase_id
Where department_name IN ("Shoes","Trousers","Shirts")
AND item IN (
'red shoes',
'green shoes',
'blue shoes'
AND department_name IN (
'red trousers',
'green trousers',
'blue trousers'
AND department_name IN(
'red shirts',
'green shirts',
'blue shirts'
GROUP by 1
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
