Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




HIVE SELECT ORDER BY Statement

The ORDER BY clause is used to fetch the data in ascending or descending order.


Syntax:


SELECT column1,column2,...,columnN from <tablename> ORDER BY column1,column2,..,columnN ASC|DESC;

column1,column2 are the columns of the table.




Example:

Sorting in ascending order

SELECT * from Employee ORDER BY city;

emp_id name city salary
104 Rahul Bangalore 60000
101 John California 50000
103 Harry Delhi 80000
105 Sakil Delhi 90000
102 Tom Mumbai 40000

Sorts the city in ascending order.



Sorting in descending order

SELECT * from Employee ORDER BY city DESC;

emp_id name city salary
102 Tom Mumbai 40000
103 Harry Delhi 80000
105 Sakil Delhi 90000
101 John California 50000
104 Rahul Bangalore 60000


Sorting in ascending order with two columns

SELECT * from Employee ORDER BY city,salary;

emp_id name city salary
104 Rahul Bangalore 60000
101 John California 50000
103 Harry Delhi 80000
105 Sakil Delhi 90000
102 Tom Mumbai 40000