rotorblade
Programmer
I'm trying to retrieve only records from table A joined to table B where A.id = B.id and there is a matching record in table B for EVERY value in a list of values for B.filter.
For instance, given the following two tables:
-------- Table A ----------
| id | description |
---------------------------
| 2 | "blu + yel" |
| 3 | "just blue" |
| 4 | "just blue" |
---------------------------
-------- Table B ----------
| id | filter |
---------------------------
| 2 | yellow |
| 2 | blue |
| 3 | blue |
| 4 | blue |
---------------------------
I need a where clause to join A and B such that I get only records from A where there is a matching record in B with filter='yellow' _AND_ a matching record in B with filter='blue' (i.e only id=2)
The _OR_ version is simple (B.value IN ('yellow', 'blue')) but that returns ANY record from A where ANY value matches. I need only the records from A where __ALL__ values are present in B.
Please help!!
Thanks!
-R
For instance, given the following two tables:
-------- Table A ----------
| id | description |
---------------------------
| 2 | "blu + yel" |
| 3 | "just blue" |
| 4 | "just blue" |
---------------------------
-------- Table B ----------
| id | filter |
---------------------------
| 2 | yellow |
| 2 | blue |
| 3 | blue |
| 4 | blue |
---------------------------
I need a where clause to join A and B such that I get only records from A where there is a matching record in B with filter='yellow' _AND_ a matching record in B with filter='blue' (i.e only id=2)
The _OR_ version is simple (B.value IN ('yellow', 'blue')) but that returns ANY record from A where ANY value matches. I need only the records from A where __ALL__ values are present in B.
Please help!!
Thanks!
-R