当前位置:网站首页>PHP MySQL order by keyword
PHP MySQL order by keyword
2022-07-03 17:51:00 【Crooning ~ shallow singing】
ORDER BY key word
ORDER BY Keywords are used to sort the data in the recordset .
ORDER BY Keywords sort records in ascending order by default .
If you want to sort in descending order , Please use DESC keyword .
grammar
SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC
To learn more about SQL Knowledge , Please visit our SQL course .
example
The following example selects "Persons" All the data stored in the table , And according to "Age" Column to sort the results :
<?php
$con=mysqli_connect("localhost","username","password","database");
// Detection connection
if (mysqli_connect_errno())
{
echo " The connection fails : " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons ORDER BY age");
while($row = mysqli_fetch_array($result))
{
echo $row['FirstName'];
echo " " . $row['LastName'];
echo " " . $row['Age'];
echo "<br>";
}
mysqli_close($con);
?>The above results will be output :
Glenn Quagmire 33 Peter Griffin 35
Sort by two columns
You can sort by multiple columns . When sorting by multiple columns , The second column is used only if the values of the first column are the same :
SELECT column_name(s) FROM table_name ORDER BY column1, column2
边栏推荐
- Getting started with deops
- The third day of writing C language by Yabo people
- [教程]在 CoreOS 上构建你的第一个应用
- Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
- AcWing 271. 杨老师的照相排列【多维DP】
- 1164 Good in C
- TensorBoard快速入门(Pytorch使用TensorBoard)
- 分布式的任务分发框架-Gearman
- PHP processing - watermark images (text, etc.)
- Applet setting multi account debugging
猜你喜欢

Notes on problems -- watching videos on edge will make the screen green

Qt调节Win屏幕亮度和声音大小

Type conversion, variable

鸿蒙第四次培训

Applet setting multi account debugging

Deops入门

Research on Swift

微服务组件Sentinel控制台调用

Interviewer: why is the value nil not equal to nil?

Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
随机推荐
AcWing 4489. Longest subsequence
Type conversion, variable
[combinatorics] recursive equation (special solution example 1 Hannover tower complete solution process | special solution example 2 special solution processing when the characteristic root is 1)
Detailed explanation of common network attacks
分布式的任务分发框架-Gearman
How to deploy applications on kubernetes cluster
Remote office tools sharing | community essay solicitation
Leetcode 108 converts an ordered array into a binary search tree -- recursive method
MySQL grouping query
Draw some simple graphics with MFC
SQL injection database operation foundation
WEB-UI自动化测试-最全元素定位方法
PHP processing - watermark images (text, etc.)
Records of long objects and long judgments in the stream of list
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
STM32实现74HC595控制
[combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
i++与++i的区别:通俗易懂的讲述他们的区别
VM11289 WAService. js:2 Do not have __ e handler in component:
POM in idea XML graying solution