Subject AW: [firebird-support] exists() in stored procedure with ordered
Author Christian Waldmann
>Christian,
>
>> the following query works in ISQL with firebird 2.1.2:
>>
>> select animalid
>> from PROCGETACTIVEANIMALS( :reportdate )
>> where not exists(
>> select tav.UIDANIMAL, tav.LOGTIMESTAMP
>> from TBLANIMALDAYREPORT tav
>> where (tav.UIDANIMAL = animalid ) and (tav.KIND = 'R')
>> order by tav.LOGTIMESTAMP
>> )
>
>While it does "work", it is poor SQL.
>
>You need to re-think how EXISTS operates -- it simply checks if any
record matches the criteria.
>
>So don't think of it as a standand alone query which returns a
meaningful or ordered result set, but rather a basic query to define a
criteria.
>
>The more appropriate SQL statement would be
>
>select animalid
>from PROCGETACTIVEANIMALS( :reportdate )
>where not exists(
>select 1
>from TBLANIMALDAYREPORT tav
>where (tav.UIDANIMAL = animalid) and (tav.KIND = 'R')
>)
>
>Sean

Hello Sean



After starting a new day and re-thinking it is now clear to me that an
ORDERED clause within an EXISTS is useless.



Now I use a WHERE clause with an addition condition and so, the order is
not needed anymore



where (tav.UIDANIMAL = animalid ) and (tav.KIND = 'R') and
(tav.LOGTIMESTAMP ) > :reportdate)



Many than for your thoughts

Christian



[Non-text portions of this message have been removed]