让我们首先创建一个表-
mysql> create table DemoTable( FirstName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris'); mysql> insert into DemoTable values('Adam'); mysql> insert into DemoTable values('John'); mysql> insert into DemoTable values('Sam'); mysql> insert into DemoTable values('Mike'); mysql> insert into DemoTable values('David');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+ | FirstName | +-----------+ | Chris | | Adam | | John | | Sam | | Mike | | David | +-----------+ 6 rows in set (0.00 sec)
这是对列表进行排序并在最后设置固定结果的查询。我们在末尾设置了名称“ Mike”-
mysql> select *from DemoTable order by FirstName='Mike',FirstName;
这将产生以下输出-
+-----------+ | FirstName | +-----------+ | Adam | | Chris | | David | | John | | Sam | | Mike | +-----------+ 6 rows in set (0.00 sec)