使用 MySQL 选择语句检索姓氏相似(但大小写不同)的相同名字?
mysqlmysqli database
首先我们创建一个表 −
mysql> create table DemoTable623 (FirstName varchar(100),LastName varchar(100),Age int); Query OK, 0 rows affected (0.76 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable623 values('John','Smith',23); Query OK, 1 row affected (0.66 sec) mysql> insert into DemoTable623 values('Adam','smith',23); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable623 values('Chris','Brown',24); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable623 values('Robert','brown',21); Query OK, 1 row affected (0.22 sec)
使用 select 语句显示表中的所有记录 −
mysql> select *from DemoTable623;
这将产生以下输出 −
+-----------+----------+------+ | FirstName | LastName | Age | +-----------+----------+------+ | John | Smith | 23 | | Adam | smith | 23 | | Chris | Brown | 24 | | Robert | brown | 21 | +-----------+----------+------+ 4 rows in set (0.00 sec)
这是使用 MySQL 的选择语句的查询 −
mysql> select FirstName from DemoTable623 where lower(LastName) ='smith';
这将产生以下输出 −
+-----------+ | FirstName | +-----------+ | John | | Adam | +-----------+ 2 rows in set (0.00 sec)