Display only a specific duplicate record in MySQL

MySQLMySQLi Database

To display only a specific duplicate record, use the MySQL LIKE operator −

select *from yourTableName where yourColumnName like ‘yourValue’;

Let us first create a table −

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

Insert some records in the table using insert command −

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)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

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

Here is the query to get a specific duplicate record −

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

This will produce the following output −

+------+
| Name |
+------+
| John |
| John |
+------+
2 rows in set (0.03 sec)
raja
Published on 13-Dec-2019 06:22:40
Advertisements