In postgreSQL, how can i return a table containing 0 if my table is empty and a table containing 1 if my table has rows?
I need to do it in SQL, not using any other language
Use:
SELECT CASE
WHEN EXISTS (SELECT * FROM foo LIMIT 1) THEN 1
ELSE 0
END
EDIT: Added LIMIT 1 to speed up query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With