Hi guys I've got a situation like this:
There is a table WH_AT:
ID | Warehouse_ID | Attribute_ID |
---|---|---|
1 | W01 | 101 |
2 | W01 | 201 |
3 | W02 | 106 |
4 | W02 | 209 |
5 | W03 | 156 |
6 | W03 | 201 |
And what I want to search, is all warehouses (warehouse_ID) that has BOTH Attribute_ID 101 and 201 for example.
Now I know that select * from WH_AT where Attribute_Id = 101 and Attribute = 201
won't work, but I tried self-joins and failed miserably (i tried:
select *
from WH_AT w1
join WH_AT w2 on w1.ID = w2.ID
where w1.Attribute_ID = 101 and w2.Attribute_ID = 201
unfortunately got some errors, and while specyfying w1.ID != w2.ID
it returned basicaly the whole table.
How do i get Warehouse_IDs that has both Attributes: 101 and 201? And how to write a query as simple as possible, to be possibly most effective?