您可以CONCAT()
为此使用MySQL中的函数。让我们首先创建一个表-
mysql> create table DemoTable ( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientFirstName varchar(20), ClientLastName varchar(20) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(ClientFirstName,ClientLastName) values('John','Smith'); mysql> insert into DemoTable(ClientFirstName,ClientLastName) values('John','Miller'); mysql> insert into DemoTable(ClientFirstName,ClientLastName) values('Carol','Taylor'); mysql> insert into DemoTable(ClientFirstName,ClientLastName) values('Adam','Smith');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+-----------------+----------------+ | ClientId | ClientFirstName | ClientLastName | +----------+-----------------+----------------+ | 1 | John | Smith | | 2 | John | Miller | | 3 | Carol | Taylor | | 4 | Adam | Smith | +----------+-----------------+----------------+ 4 rows in set (0.00 sec)
以下是获取组合字段结果的查询-
mysql> select ClientId from DemoTable where concat(ClientFirstName,' ',ClientLastName) LIKE 'Jo%';
这将产生以下输出-
+----------+ | ClientId | +----------+ | 1 | | 2 | +----------+ 2 rows in set (0.00 sec)