MySQL中是否有默认的ORDER BY值
MySQL中没有默认的ORDER BY值。您需要明确指定ORDER BY子句。以下是语法-
ORDER BY ASC;OR
ORDER BY DESC;
让我们首先创建一个表-
create table DemoTable-> (
-> StudentName varchar(100)
-> );
使用插入命令在表中插入一些记录-
insert into DemoTable values('Sam');insert into DemoTable values('Chris');
insert into DemoTable values('David');
insert into DemoTable values('Bob');
insert into DemoTable values('Robert');
使用select语句显示表中的所有记录-
select *from DemoTable;
输出结果
这将产生以下输出-
+-------------+| StudentName |
+-------------+
| Sam |
| Chris |
| David |
| Bob |
| Robert |
+-------------+
5 rows in set (0.00 sec)
情况1-如果您希望结果按升序排列-
select *from DemoTable order by StudentName asc;
输出结果
这将产生以下输出-
+-------------+| StudentName |
+-------------+
| Bob |
| Chris |
| David |
| Robert |
| Sam |
+-------------+
5 rows in set (0.00 sec)
情况2-如果您希望结果按降序排列-
select *from DemoTable order by StudentName desc;
输出结果
这将产生以下输出-
+-------------+| StudentName |
+-------------+
| Sam |
| Robert |
| David |
| Chris |
| Bob |
+-------------+
5 rows in set (0.00 sec)
以上是 MySQL中是否有默认的ORDER BY值 的全部内容, 来源链接: utcz.com/z/331596.html