After completion with where Queries. Let's move ahead with the sorting of data in terms of Ascending and descending order. This kind of sorting in SQL is done using the ORDER BY Clause.
Let's move ahead with the queries based on an order by clause:
QUERY 1:LIST OUT THE EMPLOYEE ID, LAST NAME IN ASCENDING ORDER BASED ON THE EMPLOYEE ID.
Now as the query suggestions, we need to arrange the data, where the last name of an employee is sorted by arranging Employee ID in Ascending Order. Follow the below code to perform the same:
Select ID, Last_Name from employee order by ID;
QUERY 2: LIST OUT THE EMPLOYEE ID, NAME IN ASCENDING ORDER BASED ON SALARY.
Here, in this query, we need to sort the ID of the employee, by arranging the Salary of the employee in ascending order.
Select ID, First_Name, Middle_Name, Last_Name,Salary from Employee order by Salary;
QUERY 3: LIST OUT THE EMPLOYEE DETAILS ACCORDING TO THEIR LAST NAME IN ASCENDING ORDER.
This query demands, to arrange Data by arranging the Last_Name of the Employee in ascending order.
Find below the code, that performs the same task:
Select * from Employee Order by Last_Name;
QUERY 4: LIST OUT THE EMPLOYEE DETAILS ACCORDING TO THEIR LAST NAME IN ASCENDING ORDER AND THEN ON DEPARTMENT_ID IN DESCENDING ORDER.
To apply different sorting for two different types of columns follows the code as written below:
Select * from Employee order by Last_Name ASC,Department_id DESC;