Skip to main content

SQL ORBER BY

How to Order Database Table ?
                                        ORDER BY Keyword is used to sort the record-set  in database table in ascending or descending order. By default sql sort record-set in ascending order.

SELECT Column1, Column2, Column3...... FROM table_name ORDER BY Column1, Column2, Column3 DESC/ASC
  • DESC to sort in descending order.
  • ASC to sort in ascending order.
ORDER BY Numerical Value;
Employee
 id     Emp_name      Age         Salary Dept_id
 1 Jebas  35 80000 2
 2             Thomas  30 40000 1
 3 Mark              25 40000 2
 4         Harry  42 62500 2
 5 Willam  45 125000 1
 6 James  32 35000 3
 7 Mock  22 15000 3
 8 Sherin  23 12000 7

SELECT Emp_name, Salary FROM Employee ORDER BY salary ASC.
This statement order the table by salary in ascending order..
Employee
 Emp_name     Salary   
 Sherin 14000 
 Mock 15000
 James 5000
 Thomas 40000
 Mark 40000
 Harry 62500
 Jebas 80000
 Willam 125000    
SELECT Emp_name, Salary FROM Employee ORDER BY salary DESC;
This statement order the by salary in descending order
Employee
 Emp_name     Salary
 Willam 125000
 Jebas 80000
 Harry 62500
 Mark 40000
 Thomas 40000
 James 35000
 Mock 15000
 Sherin 1$000

ORDER BY String;
SELECT Emp_name, Salary FROM Employee ORDER BY Emp_name ASC.
This statement order the table by employee name in ascending order
Employee
 Emp_name     Salary
 Harry 62500
 James 35000
 Jebas 80000
 Mark 40000
 Mock 15000
 Sherin 14000
 Thomas 40000
 Willam 125000



Thank You. Like Share and Subscribe 👍 folowlect.com

Comments