order by in sql
ORDER BY: is for sorting result
either in descending or ascending order.
order by in sql
ORDER BY: is for sorting result
either in descending or ascending order.
order by 1
SELECT DISTINCT department
FROM employees
ORDER BY 1
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.
it simply means sorting the view or table by 1st column of
query's result.
------------------------------------------------
SELECT department, hire_date
FROM employees
ORDER BY 2
It would order by hire_date since it's the second
column in the results.
THIS IS NOT A RECOMMENDED PRACTICE AS THE COLUMNS CAN CHANGE LATER!
This can cause a lot of confusion if multiple people work on the
code base.
It's better to assign an alias to each column name rather
than using a column number.
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us