SQL Order By Cheat Sheet

Database cleanup 1038x576

This is a cheat sheet that I have put together for keeping track of the results of ordering different types of columns in ASC and DESC order and the rules around each.  This order is fairly standard for most ANSI database servers.  However I do not believe that there is anything in the ANSI spec that dictates this as a requirement.

Sort type
DESC
ASC (default)
NULL NULL last NULL first
Numerical 10

9

8

...

1

0

0

1

2

..

10

11

Alphabetical CI

(CI vs CS has an impact here as CI sees no difference between A and a but CS does! see below)

Z

Y

X

...

A

A

B

C

...

Z

Dates 2019

2018

2017

...

1907

1907

1908

1909

...

2019

ALPHAbetical CS Lowercase first

Uppercase last

Uppercase first

Lowercase last

 

Leave a Reply

Your email address will not be published. Required fields are marked *