By 25/02/2016 12 Comments

What Is ORDER BY Clause In SQL?

  • The ORDER BY clause is used for sorting purpose of return result sets from database table(s).
  • The ORDER BY clause sorts the result sets of one or more columns of database table(s).
  • The ORDER BY clause uses two keywords for sorting the database tables(s): ASCĀ for sorting by ASCENDING order and DESC for DESCENDING order.
  • The ORDER BY clause sorts result sets inĀ ASCENDING order by default.

Syntax:

SELECT column_name1, column_name2
FROM table_name
ORDER BY column_name1 ASC|DESC, column_name2 ASC|DESC;

Example: ORDER BY:

SELECT user_name, user_fathers_name
FROM sm_users
ORDER BY user_name;

Example: ORDER BY ASC:

SELECT user_name, user_fathers_name
FROM sm_users
ORDER BY user_name ASC;

Example: ORDER BY DESC:

SELECT user_name, user_fathers_name
FROM sm_users
ORDER BY user_name DESC;

Example-1: ORDER BY Multiple Columns:

SELECT user_name, user_fathers_name
FROM sm_users
ORDER BY user_name, user_fathers_name;

Example-2: ORDER BY Multiple Columns:

SELECT user_name, user_fathers_name
FROM sm_users
ORDER BY user_name ASC, user_fathers_name DESC;






← Previous Tutorial


Posted in: Sql

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .