让我们首先创建一个表-
mysql> create table DemoTable ( FirstName varchar(100), CountryName varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Adam','US'); mysql> insert into DemoTable values('David','AUS'); mysql> insert into DemoTable values('Chris','UK'); mysql> insert into DemoTable values('John','US'); mysql> insert into DemoTable values('Carol','AUS');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+-------------+ | FirstName | CountryName | +-----------+-------------+ | Adam | US | | David | AUS | | Chris | UK | | John | US | | Carol | AUS | +-----------+-------------+ 5 rows in set (0.00 sec)
以下是将特定列值与相应记录连接的查询-
mysql> select concat(FirstName,' ',CountryName) AS NameWithCountry from DemoTable having NameWithCountry LIKE '%John%';
这将产生以下输出-
+-----------------+ | NameWithCountry | +-----------------+ | John US | +-----------------+ 1 row in set (0.00 sec)