SQL ORDER BY CLAUSE



The SQL ORDER BY clause is used to sort the data in ascending or descending order, based on one or more columns. Some database sorts query results in ascending order by default.

SYNTAX:

SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION
ORDER BY column_name {ASC|DESC};

EXAMPLE:
select * from student where no > 100 ORDER BY name asc;

Displays all the columns from the table student where no is greater than 100 and displays the result in ascending order.

SELECT * FROM CUSTOMERS ORDER BY NAME, SALARY;
Displays all the values from the table customer by arranging the values of name,salary in ascending order.

SELECT * FROM CUSTOMERS ORDER BY NAME DESC;

Displays the result by sorting in descending order.

No comments:

Post a Comment