如何在 MySQL 中搜索“ñ”,而不会显示包括“n”的记录?
当您搜索“ñ”时,如果您不希望所有包含“n”的记录,请使用以下语法 -
select *from yourTableName where yourColumnName LIKE '%ñ%' COLLATE utf8_spanish_ci;
我们先创建一个表。以下查询 -
mysql> create table NotIncludenDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20) -> ); Query OK, 0 rows affected (1.07 sec)
以下查询使用 insert 命令在表中插入一些记录 -
mysql> insert into NotIncludenDemo(ClientName) values('John'); Query OK, 1 row affected (0.21 sec) mysql> insert into NotIncludenDemo(ClientName) values('Johñ'); Query OK, 1 row affected (0.14 sec) mysql> insert into NotIncludenDemo(ClientName) values('Johnñy'); Query OK, 1 row affected (0.18 sec)
以下查询使用 select 语句显示表中的所有记录 -
mysql> select *from NotIncludenDemo;
这将产生以下输出 -
+----+------------+ | Id | ClientName | +----+------------+ | 1 | John | | 2 | Johñ | | 3 | Johnñy | +----+------------+ 3 rows in set (0.00 sec)
以下是搜索“ñ”的查询 -
mysql> select *from NotIncludenDemo where ClientName LIKE '%ñ%' COLLATE utf8_spanish_ci;
这将产生以下输出 -
+----+------------+ | Id | ClientName | +----+------------+ | 2 | Johñ | | 3 | Johnñy | +----+------------+ 2 rows in set (0.60 sec)
广告