Subject Re: [firebird-support] Re: The First to select
Author Ann W. Harrison
Richard Wesley wrote:
>
> I have just done something similar to check for NULLs without
> indexing (I may not have control over the database being queried):
>
> select first 1 <field> from <table> where <field> is NULL;
>
> Hopefully, this will just read records in the most convenient order
> until it hits one and then stop. Anyone know if this is any faster
> than a full table scan?

A slightly more conventional version would be

select 1
from rdb$database
where exists (select 1
from <table>
where <field> is NULL)


Either is exactly a full table scan if the field is never null, but
less than that if the field can be null.

Regards,


Ann