您可以为此使用ORDER BY。让我们首先创建一个表-
mysql> create table DemoTable ( Value int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(20); mysql> insert into DemoTable values(8); mysql> insert into DemoTable values(18); mysql> insert into DemoTable values(11); mysql> insert into DemoTable values(9); mysql> insert into DemoTable values(19); mysql> insert into DemoTable values(6); mysql> insert into DemoTable values(7);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-------+ | Value | +-------+ | 20 | | 8 | | 18 | | 11 | | 9 | | 19 | | 6 | | 7 | +-------+ 8 rows in set (0.00 sec)
以下是查询以显示MySQL中的第一个选定行-
mysql> select *from DemoTable order by (Value=9) DESC,Value DESC;
这将产生以下输出-
+-------+ | Value | +-------+ | 9 | | 20 | | 19 | | 18 | | 11 | | 8 | | 7 | | 6 | +-------+ 8 rows in set (0.00 sec)