Subject Re: [firebird-support] Check if record exist
Author Helen Borrie
At 10:04 AM 27/01/2005 +0100, you wrote:

>I want to check if a record exist in SQL. Of course I could use:
>Select Count(*) From Person Where PersId=:PersId
>and check if a what is returned is higher than 0, but if there are a lot
>of records that will take a lot of time
>
>I want to something like:
>Select First 1 Count(*) From Person Where PersId=:PersId
>
>Or
>Select Count(*) From Person Where PersId=:PersId And RecordCount<2
>
>Both do not work. How do I do this.

If you just want to check for existence and return something small:

select 1 from rdb$database
where exists (select 1 from Person where PersId=:PersId)
returns 1 if there is at least one matching row; returns empty set otherwise.

./hb