| Subject | Re: [firebird-support] Using EXISTS instead COUNT(*) | 
|---|---|
| Author | Magnus Titho | 
| Post date | 2005-06-23T07:59:32Z | 
buppcpp wrote:
where (select count(*) from table2 t2 where t2.foreignkey = t1.id) > 0
==>
select t1.id from table1 t1
where exists(select t2.id from table2 t2 where t2.foreignkey = t1.id)
--
Magnus
            > I read in the Firebird book to use EXISTS instead of SELECT COUNT(*)... Ifselect t1.id from table1 t1
> you just need to see if a record exist.
>
where (select count(*) from table2 t2 where t2.foreignkey = t1.id) > 0
==>
select t1.id from table1 t1
where exists(select t2.id from table2 t2 where t2.foreignkey = t1.id)
--
Magnus