ID | name | isSearchable |
---|---|---|
1 | foo | true |
2 | bar | true |
3 | zar | false |
I’ve got some ids
and I need to filter records where they have isSearchable = true
.
This query give as result ID = 1
because is searchable, but I would to apply the filter isSearchable
to the entire result, not row-by-row.
SELECT *
FROM my_table
WHERE id IN (1, 3)
AND isSearchable = true
So in this case I’m expecting no-results because both records should be in first isSearchable
and after that, filter the ids.
I’ve tried experimenting with sub-query etc but the in
operator (or the or
operator) but I’m not able to accomplish the result.
Maybe is something really simple, but I’ve no ideas on how to solve.
Thanks for your help.
2
Answers
How about this?
Think of a generic programming language:
The filter order can completely change the results. If you explicitly write the query so that the execution plan is not open to interpretation, you’re good.
One approach using a window function:
Check the demo here.