从具有重复列值 (名称) 的 MySQL 表中获取特定行?


让我们首先创建 -

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)

使用插入在表中插入一些记录 -

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)

使用选择从表中显示所有记录 -

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)

更新于: 12年-11月-2019

102 查看次数

开启你的 职业 生涯

完成课程获取认证

开始学习
广告