Oracle 11g: enforce a relationship between two columns in a select query
I have a table in my db which stores rows by an id and version in two separate columns e.g.,
ID VERSION DATA 1 1 ... 1 2 ... 2 1 ... 2 2 ...
What i want to do is a "select * where id and version in" query but I'm not sure of a way to keep the id and version linked, for example if my input was id_verList[(1,1),(1,2),(2,1)].
The results i want to get back with this input and the example table would be the first 3 rows but
select * from table where id in (1,1,2) and version in (1,2,1)
would return all 4 rows as the two lists are not linked.
Is there a way to enforce a relationship between the id and version without altering the table to have a combined id_ver column.
Try this query:
SELECT * FROM table_name WHERE (id,version) IN ((1,1), (1,2), (2,1))
More info: Expression Lists