I have a table numbers
:
id | n |
---|---|
1 | 1 |
2 | 2 |
3 | 5 |
4 | 7 |
5 | 9 |
And I have a table of rules
:
rule_type | n |
---|---|
LT | 2 |
GT | 7 |
GT | 9 |
EQ | 2 |
(LT – less-than, GT – greater-than, EQ – equals).
I want to select every id from numbers
, that satisfies any rule from table rules
.
Expected result
:
id |
---|
1 |
2 |
5 |
P.S. I use PostgreSQL 15.1.
2
Answers
You could try this query
See demo here
I have used your tables to create this SQLFIDDLE and wrote a query and tested it.
The following query works :
It returns the expected output :