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.

Thanks, James

Answers


Try this query:

SELECT *
 FROM table_name
 WHERE (id,version) IN ((1,1), (1,2), (2,1))

More info: Expression Lists


Need Your Help

Null Pointer Exception when trying to set a value

java for-loop nullpointerexception

So pretty much I'm making an array of obvjects called Spots which symbolise the different faces of a dice.

Is sending mails through SMTP better than php mail() in terms of server load?

php email smtp server-load

I am sending >1000 mails per day for a mailing list. Right now they are all sent with php mail(). Would it put less load on the server if they were sent through a script with SMTP ?