Subject | RE: [firebird-support] exists() in stored procedure with ordered |
---|---|
Author | Leyne, Sean |
Post date | 2009-10-21T17:05:20Z |
Christian,
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
> the following query works in ISQL with firebird 2.1.2:While it does "work", it is poor SQL.
>
> 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
> )
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