1SELECT * FROM table_name ORDER BY col1 ASC; -- ASCending is default
2SELECT * FROM table_name ORDER BY col1 DESC; -- DESCending
3SELECT * FROM table_name ORDER BY col1 DESC, col2; -- col1 DESC then col2 ASC
1//this_for_descending_order..
2 SELECT * FROM TableName ORDER BY columnName DESC;
3 // this_for_ascending_order..
4SELECT * FROM TableName ORDER BY columnName ASC;
1SELECT *
2FROM employees
3ORDER BY employees.employee_id DESC ;
4· Ascending ( ASC)
5· Descending ( DESC)
1SELECT DISTINCT column, AGG_FUNC(column_or_expression), …
2FROM mytable
3 JOIN another_table
4 ON mytable.column = another_table.column
5 WHERE constraint_expression
6 GROUP BY column
7 HAVING constraint_expression
8 ORDER BY column ASC/DESC
9 LIMIT count OFFSET COUNT;
1SQL order of execution defines the
2execution order of clauses.
3
4-Select
5It starts execution with
6-from (Choose and join tables to get base data)
7after from
8-where ( filters base data )
9-group by (Aggregates base data)
10-having (filters aggregated data)
11-select (returns final data)
12-order by (sorts the final data)
13-limit (limits the returned data to a row count)
14
15Only select and from are mandatory
1Used to sort the result data in ascending (default) or descending order
2through the use of ASC or DESC keywords.
3Example: Returns countries in alphabetical order.
4SELECT * FROM countries
5ORDER BY name;