Today I Learned

hashrocket A Hashrocket project

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);
 Here exists a record
(1 row)

select 'no record :(' as word where not exists (select 1 where true);
(0 rows)
See More #sql TILs
Looking for help? Hashrocket developers believe that data quality is as important as code quality. We enjoy all the challenges of relational databases, from finding the fastest index, to structuring data to fit the needs of an application. We're eager to share our experiences; check out PG Casts, our series of free PostgreSQL screencasts.