让我们首先创建一个表-
mysql> create table DemoTable ( FirstName varchar(100), LastName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Chris','Brown'); mysql> insert into DemoTable values('Adam','Smith'); mysql> insert into DemoTable values('Carol','Taylor'); mysql> insert into DemoTable values('David','Miller');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Chris | Brown | | Adam | Smith | | Carol | Taylor | | David | Miller | +-----------+----------+ 4 rows in set (0.00 sec)
以下是执行串联的查询。在这里,我们有名字和姓氏。这样一来,所有字符串值的开头还会附加一个字符串-
mysql> select concat('Hello ',FirstName,' ',LastName) from DemoTable;
这将产生以下输出-
+-----------------------------------------+ | concat('Hello ',FirstName,' ',LastName) | +-----------------------------------------+ | Hello Chris Brown | | Hello Adam Smith | | Hello Carol Taylor | | Hello David Miller | +-----------------------------------------+ 4 rows in set (0.00 sec)