Check to see if a subquery returns any records
A subquery may or may not return results. And you may want to make decisions for your data set based on that.
select 'Here exists a record' as word where not exists (select 1 where false);
word
-----------------
Here exists a record
(1 row)
select 'no record :(' as word where not exists (select 1 where true);
word
------
(0 rows)
Tweet