官术网_书友最值得收藏!

ORDER BY clause

The ORDER BY helps us in retrieving records in an ordered manner. This provides sorted data on a particular column in an ascending or a descending manner. By default, it will sort in ascending order but we can also explicitly specify the sorting manner with ASC and DESC keyword. If we specify ASC then it will sort in an ascending order while DESC keyword will sort in descending order. Here is the query which will find all users in a sorted manner in an ascending order on city column.

SELECT * FROM users ORDER BY city ASC;

Sorting in multiple columns is also possible using ORDER BY clause. We can pass multiple columns as shown in below query where we have ordered by city and username column.

SELECT * FROM users ORDER BY city, username;
主站蜘蛛池模板: 广水市| 民丰县| 鞍山市| 凤台县| 博湖县| 古交市| 保亭| 乌苏市| 博罗县| 闵行区| 神农架林区| 布拖县| 望城县| 海安县| 板桥市| 惠州市| 娱乐| 呈贡县| 龙江县| 崇州市| 隆化县| 大庆市| 渝中区| 灌阳县| 塔城市| 莒南县| 宣汉县| 连州市| 本溪| 锦州市| 凉城县| 翁牛特旗| 诸暨市| 崇明县| 天镇县| 宁河县| 屯留县| 南投县| 汕尾市| 余江县| 宁夏|