What is the purpose of Order By 1 in SQL select statement?

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:

  1. It’s not obvious/explicit
  2. If the column order changes, the query is still valid so you risk ordering by something you didn’t intend

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)