I have a search query including one table and two columns.
Select *
from Gecoserv _a
where _a.typeOfEcosystem IN (:typeNameList)
AND _a.service IN (:serviceNameList)
It works but it's not giving the result I wanted
Let's say:
typeNameList = { Freshwater, Saltwater, Dunes }
serviceNameList = {Habitat, Food, Recreation }
I want the grid to show only the single combinations (Freshwater-Habitat, Saltwater-Food and Dunes-Recreation etc.) but it shows also other combinations (ex: Freshwater-Recreation).
In other words : The query results show
[0,0],[0,1],[0,2],
[1,0],[1,1],[1,2],
[2,0],[2,1],[2,2].
But I want to see ONLY : [0,0],[1,1],[2,2]
.
I know that I have to add something to the end of query. I tried many things but couldn't figure out a perfect solution.
Is there anybody who can help me with that?
Regards,
Melih
I think this can't be done, when this is the only information you've got. The relation between the values of the parameters, is their position in their list. There is no option to relate and/or preserve these positions in SQL.
What influence do you have on creating the sql-statement?
If you can iterate over the lists in code and dynamically create the sql, you could come to a solution like this:
For an example of how to parameterize this, have a look at this answer.
An alternative: splitting strings
Your main problem is to preserve the "rank"/"position" of the parameters in their lists. This can be done, by replacing your lists by strings and break them up.
I used this example of a splitting a string in sql.
The resulting query (made with this Fiddle) then looks like:
Will this work for your scenario? (Answer: yes, almost...)
And finally without a function