Monday, April 14, 2014

T SQL Tutorial: ORDER BY

In T SQL Tutorial check how to use ORDER BY clause with syntax and examples.

One Liner
The SQL ORDER BY clause is used to sort the records in the result set for a SELECT statement.

Syntax
The syntax for the SQL ORDER BY clause is:

SELECT expressions
FROM tables
WHERE conditions
ORDER BY expression [ ASC | DESC ];

Thing to Remember
If the ASC or DESC option is not provided in the ORDER BY clause, the results will be sorted by expression in ascending order (which is equivalent to "ORDER BY expression ASC").
Order by clause can’t be used in a view definition.
Order by cant be used in a sub query having aggregate functions in select statement

No comments:

Post a Comment