
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Fetch Specific Rows from MySQL Table with Duplicate Column Names
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)
Advertisements