Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
Order By Clause in SQL - Testingpool

Order By Clause in SQL

Order By Clause in SQL is used to sort the resultset in ascending or descending order.

Key – Points :

  • By default it sorts the result in Ascending order.
  • Asc Keyword is used for Ascending Order and Desc Keyword is used for Descending  Order.
  • The Sorting can be done on the basis of one or more then one column.
  • Besides the Column names, Sorting can also be done on the basis of Column Position.
  • Order By always comes in the last of the Select sequence.

Syntax :

Sorting in Ascending Order –

SELECT <Col Name> from <Tablename> WHERE <Condition> ORDER BY <Col > Asc ;

SELECT <Col Name> from <Tablename> WHERE <Condition> ORDER BY <Col >;

Note : If no order is specified then by default it takes Ascending order.

Sorting in Descending Order –

SELECT <Col Name> from <Tablename> WHERE <Condition> ORDER BY <Col > DESC;

Sorting on the basis of multiple columns –

SELECT <Col Name> from <Tablename> WHERE <Condition> ORDER BY <Col 1> DESC , <Col 2 > ASC ;

Sorting on the bais of relative position –

SELECT <Col Name> from <Tablename> WHERE <Condition> ORDER BY <Col Position> DESC;

SELECT <Col Name> from <Tablename> WHERE <Condition> ORDER BY <Col Position> ASC;

 

Avatar photo

Shikha Katariya

Shikha

You may also like...