SQL order by keyword

      No Comments on SQL order by keyword

Sql order by keyword is used to sort the result set in some order.
The order by keyword sorts the result-set by one or more column.The order by keyword sorts the result-set in ascending order by default.To sort the set in descending order one can use DESC keyword.

Syntax:

SELECT column_name, column_name
FROM table_name
ORDER BY column_name ASC|DESC, column_name ASC|DESC;

Demo databse:

C.idC.nameC.contactC.address
123eed3Ramesh987654321#12,sec-4 mohali
aa22103Tarun987650000#12,sec-14 b chd
00146hhSia812300912#212,sec-86 panchukula
144dcv4Rahul700912366#001,sec-19 c chd
  • Order by :SELECT * FROM Customers ORDER BY C.name;
    C.idC.nameC.contactC.address
    144dcv4Rahul700912366#001,sec-19 c chd
    123eed3Ramesh987654321#12,sec-4 mohali
    00146hhSia812300912#212,sec-86 panchukula
    aa22103Tarun987650000#12,sec-14 b chd
  • Order by DESC :SELECT * FROM Customers ORDER BY C.name DESC;
    C.idC.nameC.contactC.address
    aa22103Tarun987650000#12,sec-14 b chd
    00146hhSia812300912#212,sec-86 panchukula
    123eed3Ramesh987654321#12,sec-4 mohali
    14dcv4Rahul700912366#001,sec-19 c chd

Leave a Reply

Your email address will not be published. Required fields are marked *