SQL Golf: 5 SQL Tricks You Should (Probably) Never Use
This title could be clearer and more informative.Try out Clickbait Shieldfor free (5 uses left this month).
SQL golf challenges developers to write the shortest possible queries. This article explores five extreme techniques from the Quackmas 2025 competition: column position references (#N), boolean math for counting (sum(condition)), the mode() function to replace GROUP BY/ORDER BY/LIMIT, comma join syntax, and DuckDB-specific
Table of contents
How we got hereThe basics: every character countsBoolean math: the trick that makes you feel smartThe mode() trick: replacing three clauses with one functionJoin golf: comma syntax is backDuckDB shortcuts you might not know aboutThe subtraction trick: my favorite solutionThe final leaderboardShould you golf in production?Try it yourselfSort: