A very common misconception I often encounter with SQL users is the idea that DISTINCT is something like a function, and that it can take parenthesised arguments. Just recently, I’ve seen this Stack Overflow question where the OP was looking for a way to express this in jOOQ: Notice the parentheses around (emp.id), which look … Continue reading SQL DISTINCT…
#distinct on
3 posts
2 Mar 2020
9 Sept 2019
A nice little gem in PostgreSQL’s SQL syntax is the DISTINCT ON clause, which is as powerful as it is esoteric. In a previous post, we’ve blogged about some caveats to think of when DISTINCT and ORDER BY are used together. The bigger picture can be seen in our article about the logical order of … Continue reading Using DISTINCT…
13 Jul 2018
One of the things that confuse SQL users all the time is how DISTINCT and ORDER BY are related in a SQL query. The Basics Running some queries against the Sakila database, most people quickly understand: This returns results in an arbitrary order, because the database can (and might apply hashing rather than ordering to … Continue reading How SQL…