I have a table that looks like this:
| ID | KEY | FILTER_NAME | FILTER_VALUE | VALUE |
|---|---|---|---|---|
| 1 | a | country | USA | value1 |
| 2 | a | inRockBand | true | value2 |
| 3 | a | value3 | ||
| 4 | b | city | MADRID | value4 |
| 5 | b | isLawer | true | value5 |
| 6 | b | value6 |
I would like to create a query that can receive generic filter (optional) parameters and fetches a single row per key accordingly (when optional filters don't match - the query will return the row with null filter name\value as these are the default rows)
for example:
select * from table where filterName = 'country' and filter_value = 'SPAIN'
will return:
| ID | KEY | FILTER_NAME | FILTER_VALUE | VALUE |
|---|---|---|---|---|
| 3 | a | value3 | ||
| 6 | b | value6 |
while
select * from table where filterName = 'inRockBand' and filter_value = 'true'
will return:
| ID | KEY | FILTER_NAME | FILTER_VALUE | VALUE |
|---|---|---|---|---|
| 2 | a | inRockBand | true | value2 |
| 6 | b | value6 |
if several filters matches several keys we should take any one key