Select based on list of pairs

netezzaqueryselect

I have a table with two main columns, id1 and id2:

drop table if exists pairs;
create table pairs (id1 int, id2 int);
insert into pairs values
    (1,2), (1,3), (3,1), (2,4), (5,4), (3,6), (7,8);

I want to select rows which have these pairs [(1,2),(5,4),(3,1)]. This array could have more than 500 items, so how I can write a select query to select those rows?
I am using 'Netezza' database but I need to find the logic to do this, I can figure out how to implement this logic in my database engine.

Best Answer

I would start with:

SELECT id1, id2
FROM pairs
WHERE id1 IN (1,5,3) AND id2 IN (2,4,1)

The '1,5,3' and '2,4,1' can also be results from another query.