~/devreads

#distinct on

3 posts

2 Mar 2020

lukaseder 1 min read

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…

sqldistinctdistinct ontop 1 per category

9 Sept 2019

lukaseder 1 min read

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…

sqldistinct onfirst valuelogical operations orderlogical order of operations

13 Jul 2018

lukaseder 1 min read

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…

sqldistinctdistinct onorder byorder of operations