SQL Certification - SPLessons

SQL Certification Sorting

Home > Lesson > Chapter 25
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQL Certification Sorting

Sorting

shape Description

Sorting is similar to "order by clause" that arrange data of a table either in ascending order or descending order based on single column i.e., Select * from the table name will show all the rows from the table. And this sorting clause is used to arrange the specific column in ascending or descending order. These are utilized to sort the information in descending or ascending order, in view of at least one segments. Some database sorts question brings about climbing request as a matter of course.

shape Syntax

The syntax for Sorting clause is as follows:
Select * from <table_name> ORDER BY <column_name> DESC;
table_name=>Any accurate table. column_name =>The condition that one can perform on a column by using Order by clause.

shape Examples

By viewing the below example, the concept of sorting clause can be easily understood. [sql]sql> select * from employee; +--------+-------+-------+ | emp_id | ename | sal | +--------+-------+-------+ | 1001 | mike | 12000 | | 1002 | rambo | 13000 | +--------+-------+-------+ 2 rows in set (0.00 sec) sql> select * from employee order by sal desc; +--------+-------+-------+ | emp_id | ename | sal | +--------+-------+-------+ | 1002 | rambo | 13000 | | 1001 | mike | 12000 | +--------+-------+-------+ 2 rows in set (0.06 sec)[/sql] The above example tells that, when sort clause operation is performed on a column name like salary, then it automatically displays the entire details of employees in descending order.

Summary

shape Key Points

  • Sorting - Used to arrange the data in a increasing or decreasing order.