当前位置:网站首页>PHP MySQL Order By keywords

PHP MySQL Order By keywords

2023-01-19 15:32:04T0620514

The ORDER BY keyword is used to sort the data in the recordset.


ORDER BY keywords

The ORDER BY keyword is used to sort the data in the recordset.

The ORDER BY keyword sorts the records in ascending order by default.

If you want to sort in descending order, use the DESC keyword.

Grammar

SELECT column_name(s)FROM table_nameORDER BY column_name(s) ASC|DESC

To learn more about SQL, visit our SQL Tutorial.

Example

The following example selects all the data stored in the "Persons" table and sorts the results based on the "Age" column:

";}mysqli_close($con);?>

The above result will output:

Glenn Quagmire 33Peter Griffin 35


Sort by two columns

You can sort by multiple columns.When sorting by multiple columns, the second column is only used if the first column has the same value:

SELECT column_name(s)FROM table_nameORDER BY column1, column2
原网站

版权声明
本文为[T0620514]所创,转载请带上原文链接,感谢
https://chowdera.com/2023/019/202301191525102724.html

随机推荐