I need to select all IDs from one table with columns ID and X, WHERE X = 'Y'. For each of those IDs, I need to look up some stuff in a different table:
If the ID does not exist, it gets no row in the final result.
If the ID does exist, I want to do some logic to figure out if it gets a row. For simplicity, assume that the logic is: if column Q > 0.
So the final result is simply a column of IDs, throwing out some because they are disqualified for one of two reasons as above.
thanks.
This is what
JOINs are made for.This will select all records in table1 (which have IDs) and then remove any records that do not have a matching record in table2 or do not have a Q > 0.