当前位置:网站首页>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
边栏推荐
- As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
- MinGW compile boost library
- Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
- Keepalived 设置不抢占资源
- Market demand survey and marketing strategy analysis report of global and Chinese pet milk substitutes 2022-2028
- [Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
- ES6类的继承
- win32:堆破坏的dump文件分析
- STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
- Kotlin的協程:上下文
猜你喜欢
Talk about the design and implementation logic of payment process
Vs2013 has blocked the installer, and ie10 needs to be installed
How to purchase Google colab members in China
Tensorboard quick start (pytoch uses tensorboard)
MySQL has been stopped in the configuration interface during installation
Golang unit test, mock test and benchmark test
Introduction to SolidWorks gear design software tool geartrax
QT学习日记9——对话框
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
[combinatorics] generating function (summation property)
随机推荐
1164 Good in C
Applet setting multi account debugging
SQL injection database operation foundation
Select 3 fcpx plug-ins. Come and see if you like them
聊聊支付流程的设计与实现逻辑
Write a program to process a list container of string type. Find a special value in the container 9.27: and delete it if found. Rewrite the above procedure with deque container.
Introduction to SolidWorks gear design software tool geartrax
List的stream中Long对象与long判等问题记录
Website with JS doesn't work in IE9 until the Developer Tools is activated
【统信UOS】扫描仪设备管理驱动安装
Ssl/bio of OpenSSL_ get_ fd
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
AcWing 3438. Number system conversion
Keepalived setting does not preempt resources
数学公式(测试)
i++与++i的区别:通俗易懂的讲述他们的区别
Stm32h7 Hal library SPI DMA transmission has been in busy solution
分布式的任务分发框架-Gearman
Interviewer: why is the value nil not equal to nil?