Subject Re: SQL Puzzle of the Day
Author amoradell
If you can filter with your app, you could try :

SELECT PTYGROUPKEY, PTYROLE, PARTIESKEY FROM PARTYGROUP
WHERE (PTYROLE between :minptyrole and :maxptyrole)
and (PARTIESKEY BETWEEN :minpartieskey and maxpartieskey)

You have to find the four values and pass them to you query and therefore filter the pairs in your app.

And do you have index on PtyRole ? and PartiesKey ?

It could be significant on large datasets.

Regards

Alexandre

--- In firebird-support@yahoogroups.com, "mspencewasunavailable" <firebird@...> wrote:
>
> 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.
>