Available in versions: Dev (3.20) | Latest (3.19) | 3.18

Unnecessary ORDER BY expressions

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

When an expression is repeated in the ORDER BY clause, then the second one can be removed as it has no effect - even if it has a different value for ASC, DESC, NULLS.

Using Settings.transformPatternsUnnecessaryOrderByExpressions, the following transformations can be achieved:

-- With Settings.transformPatternsUnnecessaryOrderByExpressions active, this:
SELECT a, b FROM t ORDER BY a DESC, b, a ASC;

-- ... is transformed into the equivalent expression:
SELECT a, b FROM t GROUP BY a DESC, b;

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo