让我们首先创建一个表-
mysql> create table DemoTable ( FirstName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris'); mysql> insert into DemoTable values('Robert'); mysql> insert into DemoTable values('Mike'); mysql> insert into DemoTable values('David');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+ | FirstName | +-----------+ | Chris | | Robert | | Mike | | David | +-----------+ 4 rows in set (0.00 sec)
以下是查询,其中我们使用SELECT固定前两个值,然后显示其余值-
mysql> select 'Robert' AS FirstName UNION select 'David' AS FirstName UNION select DISTINCT(FirstName) AS FirstName from DemoTable;
这将产生以下输出-
+-----------+ | FirstName | +-----------+ | Robert | | David | | Chris | | Mike | +-----------+ 4 rows in set (0.00 sec)