What is the purpose of Order By 1 in SQL select statement?
This is useful when you use set based operators e.g. union
select cola
from tablea
union
select colb
from tableb
order by 1;
This:
ORDER BY 1
...is known as an "Ordinal" - the number stands for the column based on the number of columns defined in the SELECT clause. In the query you provided, it means:
ORDER BY A.PAYMENT_DATE
It's not a recommended practice, because:
- It's not obvious/explicit
- If the column order changes, the query is still valid so you risk ordering by something you didn't intend