Subject RE: [firebird-support] Query help needed
Author Rick Debay
The query

select mt.v2
from MyTable mt
where mt.v1 <= :MyNumber
and not exists(
select *
from MyTable mt2
where mt2.v1 > mt.v1
and mt2.v1 <= :MyNumber)

Returns the correct results, using the following plan:

PLAN (MT2 INDEX (U_UNIQUE_CONSTRAINT))
PLAN (MT INDEX (U_UNIQUE_CONSTRAINT))

However, my brain fart was worse than I thought, I've alread solved the
problem (see my response to my own post).

-----Original Message-----
From: firebird-support@yahoogroups.com
[mailto:firebird-support@yahoogroups.com] On Behalf Of Svein Erling
Tysvaer
Sent: Monday, February 05, 2007 3:54 PM
To: firebird-support@yahoogroups.com
Subject: Re: [firebird-support] Query help needed

You're right, Rick, this may be simple:

select mt.v2
from MyTable mt
where mt.v1 <= :MyNumber
and not exists(
select *
from MyTable mt2
where mt2.v1 > mt.v1
and mt2.v1 <= :MyNumber)

Set
-it has now been made simpler to donate to the future development of
Firebird at www.firebirdsql.org.

Rick Debay wrote:
> Given the number 25, I'd like to get the value 'B' back from the
> following (simplified) table:
>
> V1 V2
> -- --
> 10 A
> 20 B
> 30 C
>
> Numbers 30 and above should return 'C', and numbers below 20 should
> return 'A'.
> This should be simple, but I just can't think today.
>
> Thanks, Rick DeBay


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Visit http://www.firebirdsql.org and click the Resources item on the
main (top) menu. Try Knowledgebase and FAQ links !

Also search the knowledgebases at http://www.ibphoenix.com

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Yahoo! Groups Links




Disclaimer: This message (including attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change. RxStrategies, Inc. shall not be liable for the improper or incomplete transmission of the information contained in this communication or for any delay in its receipt or damage to your system. RxStrategies, Inc. does not guarantee that the integrity of this communication has been maintained nor that this communication is free from viruses, interceptions or interference.