For Example if I am given the following table
Id Key Value
1 A Alpha
2 B Alpha
3 A Charlie
And I took the input {(A, Charlie) and (B, Alpha)} and I asked to return all the IDs I would want it to return 2 and 3 but NOT 1.
What is the best way to do this? Can I combine it all into one query, (for speed) or would I have to run a repeat query for each value pair I received.
I think Postgresql has the most elegant solution:
SQL Fiddle Example
In SQL-SERVER 2008 and onward you can use
VALUESto build your tuples:SQL Fiddle Example
Or for a procedure you could create a key-value pair type and pass this as a parameter:
SQL Fiddle Example
For MySQL I think you may have to just build this using
AND/ORExample on SQL Fiddle
My Knowledge of other DBMS is limited, so if it is not one of the above sorry I can’t be of more help.
EDIT (With the help of a_horse_with_no_name)
The PostgreSQL syntax also works for Oracle (and I think DB2)