当前位置:网站首页>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
边栏推荐
- 国内如何购买Google Colab会员
- Where is the monitoring page of RDS database?
- Interviewer: why is the value nil not equal to nil?
- [combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
- ArrayList分析3 : 删除元素
- [combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
- 企业级自定义表单引擎解决方案(十一)--表单规则引擎1
- PHP processing - watermark images (text, etc.)
- 基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
- Brief introduction to the core functions of automatic penetration testing tool
猜你喜欢
面试官:值为 nil 为什么不等于 nil ?
Baiwen.com 7 days Internet of things smart home learning experience punch in the next day
Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
Micro service component sentinel console call
Talk about the design and implementation logic of payment process
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
[combinatorics] generating function (summation property)
Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028
SQL injection database operation foundation
鸿蒙第三次培训
随机推荐
问题随记 —— 在 edge 上看视频会绿屏
Leetcode 669 pruning binary search tree -- recursive method and iterative method
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
MySQL has been stopped in the configuration interface during installation
Assembly for unloading Loadfrom() loaded assembly - unloading the assembly loaded with assembly LoadFrom()
AcWing 3438. 数制转换
数学公式(测试)
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Play with fancy special effects. This AE super kit is for you
TensorBoard快速入门(Pytorch使用TensorBoard)
Notes on problems -- watching videos on edge will make the screen green
Keepalived 设置不抢占资源
Basic grammar of interview (Part 2)
IntelliJ 2021.3 short command line when running applications
Y is always discrete and can't understand, how to solve it? Answer: read it several times
Leetcode540: a single element in an ordered array
How to install PHP on Ubuntu 20.04
Analysis report on production and marketing demand and investment forecast of China's PVC industry from 2021 to 2026
Enterprise custom form engine solution (XI) -- form rule engine 1