Subject | Re: [ib-support] SELECT first |
---|---|
Author | Helen Borrie |
Post date | 2003-06-10T00:19:11Z |
At 04:48 PM 9/06/2003 -0700, you wrote:
If you want to fetch the data of the first matching record, you'll need to
include an ORDER BY clause to determine what "first" means.
SELECT FIRST 1 <column-list>
FROM <table>
ORDER BY <ordering-column>
If you only want to test whether any matching row exists in a different
table, then use a subquery with the WHERE EXISTS( ) predicate:
SELECT <column-list>
FROM <this-table>
WHERE EXISTS (
SELECT 1 FROM <that-table>
WHERE <search-criteria-for-that-table>)
In a stored procedure or trigger, you can also test using
IF (EXISTS (SELECT... ))
heLen
>What is the fastest way to find the first matching record for a selectAssuming you are using Firebird ---
>query without having to count all of them. I just want to know if even a
>single match exists. My understanding is that COUNT has to continue
>through the entire table.
If you want to fetch the data of the first matching record, you'll need to
include an ORDER BY clause to determine what "first" means.
SELECT FIRST 1 <column-list>
FROM <table>
ORDER BY <ordering-column>
If you only want to test whether any matching row exists in a different
table, then use a subquery with the WHERE EXISTS( ) predicate:
SELECT <column-list>
FROM <this-table>
WHERE EXISTS (
SELECT 1 FROM <that-table>
WHERE <search-criteria-for-that-table>)
In a stored procedure or trigger, you can also test using
IF (EXISTS (SELECT... ))
heLen