zmień kontrast font size: A A A
rss polski
you are at Encyclopedia of SQL >> ORDER BY

ORDER BY

ORDER BY sorts results of query by chosen column with alphabetical order or by numerical value.
By default ORDER BY sorts results of query by ascending order. But using special keywords it can be changed: ASC - use ascending order DESC - use descending order

Syntax


SELECT `column_name`
FROM `table_name`
[WHERE `column_name`]
ORDER BY 'column_name' [ASC,DESC]
[, 'column_name2' [ASC,DESC] ]

Example

Display table `people` by name and surname in alphabetical order

namesurnameage
PawełNowak3
PiotrJanik7
MichałNowak13

query


SELECT *
FROM `people`
ORDER BY `name`,`surname`

result

namesurnameage
PiotrJanik7
MichałNowak13
PawełNowak3

[ wróć na górę strony ]