Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Wednesday, April 17, 2013

9 : SQL "ORDER BY" Keyword

The ORDER BY keyword is used to sort the result-set.


The ORDER BY keyword is used to sort the result-set by a specified column.
The ORDER BY keyword sorts the records in ascending order by default.
If you want to sort the records in a descending order, you can use the DESC keyword.

The created Table is : 


Create a Database named "Studysql" and a table named "tbl_biodata"
Right click on the database Studysql and select new query.Then we can write queries as per the requirements.
( Click here to know how created this table )

ID
NAME
AGE
CITY
PHONE
1
Priyada
25
Cochin
1000000001
2
Mohan
30
Cochin
2000000002
3
Jaimon Jacob
40
Vytila
3000000003
4
Sumith
24
Kottayam
4000000004
5
Shaiju
36
Thrissur
5000000005


ORDER BY Example

Now we want to select all the persons from the table above, however, we want to sort the persons by their name.
To do so, write the command like this in SQL.

select * from tbl_biodata order by names


The result-set will look like this:


ORDER BY DESC Example


Now we want to select all the persons from the table above, however, we want to sort the persons descending by their name.

To do so, write the command like this in SQL.

SELECT * FROM tbl_biodata ORDER BY names DESC



The result-set will look like this:



SQL SELECT Syntax of the above table is : 


SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC




No comments: