让我们首先创建一个表-
mysql> create table DemoTable -> ( -> FirstName varchar(20), -> LastName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('John','Smith'); mysql> insert into DemoTable values('Chris','Brown'); mysql> insert into DemoTable values('Carol','Taylor'); mysql> insert into DemoTable values('David','Miller');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | John | Smith | | Chris | Brown | | Carol | Taylor | | David | Miller | +-----------+----------+ 4 rows in set (0.00 sec)
以下是按多列排序MySQL行的查询-
mysql> select *from DemoTable order by FirstName,LastName
输出结果
这将产生以下输出-
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Carol | Taylor | | Chris | Brown | | David | Miller | | John | Smith | +-----------+----------+ 4 rows in set (0.24 sec)