在 MySQL 中仅显示特定的重复记录

mysqlmysqli database

要仅显示特定的重复记录,请使用 MySQL LIKE 运算符 −

select *from yourTableName where yourColumnName like ‘yourValue’;

首先我们创建一个表 −

mysql> create table DemoTable
   -> (
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (1.03 sec)

使用 insert 命令在表中插入一些记录 −

mysql> insert into DemoTable values('John');
Query OK, 1 row affected (0.32 sec)
mysql> insert into DemoTable values('Chris');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('John');
Query OK, 1 row affected (0.23 sec)
mysql> insert into DemoTable values('Bob');
Query OK, 1 row affected (0.42 sec)
mysql> insert into DemoTable values('Chris');
Query OK, 1 row affected (0.30 sec)

使用 select 语句显示表中的所有记录 −

mysql> select *from DemoTable;

这将产生以下输出 −

+-------+
|  Name |
+-------+
|  John |
| Chris |
|  John |
|   Bob |
| Chris |
+-------+
5 rows in set (0.00 sec)

这是获取特定重复记录的查询 −

mysql> select *from DemoTable where Name like 'John';

这将产生以下输出 −

+------+
| Name |
+------+
| John |
| John |
+------+
2 rows in set (0.03 sec)

相关文章