Here is a simplified example of what I'm trying to do. I have two tables: A and B.
A B
----- -----
id id
name a_id
value
I want to select only the rows from A, where ALL the values of the rows from B correspond to the where clause. Sort of:
SELECT * from A INNER JOIN B on B.a_id = A.id WHERE B.value > 2
The problem with the above query is that if ANY row from B has a value> 2, I will get the corresponding row from A, and I only need a row from A, if
1.) ALL rows in B for B.a_id = A.id match WHERE, OR
2.) There are no lines in B that reference A
B is basically a filter table.
source
share