I've got the following table and I'm trying to retrieve every: name, descr, stock, address, postalcode & the city
where stock of item1 is > 10 AND stock of item2 is > 10 AND stock of item3 > 5
so I don't want the rows that only contain item1 and item2, like the ones with ID = 2
The rows of ID = 1 also won't fit because item1 its stock is < 10
Which means only rows of ID 3 and ID 4 match. But I don't want to see 6 rows, I just need two! containing the name, descr, stock, address, postalcode , city
| ID | NAME | DESCR | STOCK | ADDRESS | POSTALCODE | CITY |
| 1 | foo | item1 | 5 | addr1 | po1 | city1 |
| 1 | foo | item2 | 10 | addr1 | po1 | city1 |
| 1 | foo | item3 | 5 | addr1 | po1 | city1 |
| 2 | bar | item1 | 40 | addr2 | po1 | city1 |
| 2 | bar | item2 | 30 | addr2 | po1 | city1 |
| 3 | smth | item1 | 25 | addr3 | po3 | city1 |
| 3 | smth | item2 | 20 | addr3 | po3 | city1 |
| 3 | smth | item3 | 10 | addr3 | po3 | city1 |
| 4 | els | item1 | 45 | addr4 | po4 | city1 |
| 4 | els | item2 | 30 | addr4 | po4 | city1 |
| 4 | els | item3 | 10 | addr4 | po4 | city1 |
I think I need something like:
SELECT name, descr, stock , address, postalcode, city
FROM table1
WHERE (descr like 'item1' AND stock >10)
OR (descr like 'item2' AND stock >10) OR (descr like 'item3' AND stock >5)
GROUP BY name, descr, stock , address, postalcode, city
HAVING COUNT(distinct(somethingIdidNotFigureOutYet)) > 2
I tried to count the id, the name and even the description but it is not right. Could someone help me out with this one please. Thank you! (and sorry for the ugly table formatting)