Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does this mean "order by NULL"

Tags:

sql

oracle11g

i use oracle 11g.what does the line order by null means in the following

select f_value,row_number() over (order by null) as id 
from tableName"
like image 297
theDbGuy Avatar asked Aug 19 '14 06:08

theDbGuy


1 Answers

The OVER() clause for ROW_NUMBER() requires an ORDER BY

using ORDER BY NULL is a workaround that satifies the syntax requirement but does not actually change the order of the data. In effect it is an instruction to not order at all.

N.B.: some (myself included) prefer to use SELECT 1 instead of SELECT NULL but there is no difference in effect.

Bottom line: not great, but it works.


tip: TSQL does not permit the direct use of SELECT 1, but you may use (SELECT 1)

like image 142
Paul Maxwell Avatar answered Oct 14 '22 11:10

Paul Maxwell