Fetch specific rows from a MySQL table with duplicate column values (names)?

MySQLMySQLi Database

Let us first create a −

mysql> create table DemoTable1431
   -> (
   -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   -> EmployeeName varchar(20),
   -> EmployeeCountryName varchar(20)
   -> );
Query OK, 0 rows affected (0.62 sec)

Insert some records in the table using insert −

mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('Adam Smith','AUS');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('Chris Brown','US');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('John Doe','UK');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('Chris Brown','AUS');
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select −

mysql> select * from DemoTable1431;

This will produce the following output −

+------------+--------------+---------------------+
| EmployeeId | EmployeeName | EmployeeCountryName |
+------------+--------------+---------------------+
|          1 | Adam Smith   | AUS                 |
|          2 | Chris Brown  | US                  |
|          3 | John Doe     | UK                  |
|          4 | Chris Brown  | AUS                 |
+------------+--------------+---------------------+
4 rows in set (0.00 sec)

Following is the query to fetch specific rows from a MySQL table with duplicate column values −

mysql> select * from DemoTable1431 where EmployeeName='Chris Brown' and EmployeeCountryName='AUS';

This will produce the following output −

+------------+--------------+---------------------+
| EmployeeId | EmployeeName | EmployeeCountryName |
+------------+--------------+---------------------+
|          4 | Chris Brown  | AUS                 |
+------------+--------------+---------------------+
1 row in set (0.00 sec)
raja
Published on 12-Nov-2019 11:01:38
Advertisements