从具有重复列值(名称)的MySQL表中获取特定行?
让我们首先创建一个-
mysql> create table DemoTable1431 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20), -> EmployeeCountryName varchar(20) -> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('Adam Smith','AUS'); mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('Chris Brown','US'); mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('John Doe','UK'); mysql> insert into DemoTable1431(EmployeeName,EmployeeCountryName) values('Chris Brown','AUS');
使用选择显示表中的所有记录-
mysql> select * from DemoTable1431;
这将产生以下输出-
+------------+--------------+---------------------+ | 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)
以下是从具有重复列值的MySQL表中获取特定行的查询-
mysql> select * from DemoTable1431 where EmployeeName='Chris Brown' and EmployeeCountryName='AUS';
这将产生以下输出-
+------------+--------------+---------------------+ | EmployeeId | EmployeeName | EmployeeCountryName | +------------+--------------+---------------------+ | 4 | Chris Brown | AUS | +------------+--------------+---------------------+ 1 row in set (0.00 sec)