Lukas Eder corrects a misconception:
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:
SELECT DISTINCT (emp.id), emp.fname, emp.name FROM employee emp;
Notice the parentheses around
(emp.id)
, which look as though this is some special kind ofDISTINCT
usage, which is akin to aDISTINCT
function. The idea is often that:– The behaviour is somewhat different from omitting the parentheses
– The performance is faster, because only the ID needs to be considered for distinctness
Both of these ideas are (mostly) wrong, as Lukas shows.