Subject SQL Puzzle of the Day
Author mspencewasunavailable
I have the following table:

CREATE TABLE PARTYGROUP
(
PTYGROUPKEY Bigint NOT NULL,
PTYROLE Varchar(6) NOT NULL,
PARTIESKEY Bigint NOT NULL,
CONSTRAINT PK_PARTYGROUP_1 PRIMARY KEY (PTYGROUPKEY,PTYROLE)
);


For each PTYGROUPKEY, there are 1 or more unique PTYROLE,PARTIESKEY combinations. In my Java code, I have a list of these and would like to find the PTYGROUPKEY that exactly matches this list. I know I can do something like

SELECT PTYGROUPKEY FROM PARTYGROUP
WHERE (PTYROLE = 'A' AND PARTIESKEY = 5)
OR (PTYROLE = 'B' AND PARTIESKEY = 132)
OR ....

But (a) I'd rather use a prepared query and (b) this doesn't exclude cases where my list is actually a smaller subset of the set I retrieve with this statement.

Thanks,

Michael D. Spence
Mockingbird Data Systems, Inc.