0

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.

  • Does this array of pairs come from another table? – danblack May 20 at 23:27
  • @danblack No, Actually I want to make a store procedure to get those arrays from user, I don't think that I am gonna to save them into a separate table unless I have to do it – Majid Hojati May 20 at 23:31
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.