Answers for "order by 1 in sql"

SQL
0

order by in sql

ORDER BY: is for sorting result
either in descending or ascending order.
Posted by: Guest on January-07-2021
0

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.
Posted by: Guest on April-18-2020

Code answers related to "SQL"

Browse Popular Code Answers by Language