Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
An Efficient Way to Check for Existence of Multiple Values in SQL (jooq.org)
1 point by nalgeon on Feb 16, 2024 | hide | past | favorite | 1 comment


Using EXISTS (or NOT EXISTS) instead of COUNT() is both a well-know technique among trained DBAs and people with relational database experience, and something I rarely see developers use. I often rewrite existence or duplicate checking queries to eliminate the COUNT() and replace with EXISTS.

The author uses SELECT 1 in the example. The usual idiom is SELECT *, and query planners recognize EXISTS (SELECT * ...) and don't actually select any columns.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: