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 ASC; -- 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 q.*
2 FROM (SELECT TOP 3 *
3 FROM table
4 ORDER BY id DESC) q
5 ORDER BY q.id ASC
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