为此,可以将AND运算符与WHERE子句一起使用。让我们首先创建一个表-
mysql> create table DemoTable1616 -> ( -> StudentId int, -> StudentName varchar(20), -> StudentMarks int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1616 values(101,'Chris',56); mysql> insert into DemoTable1616 values(102,'Bob',87); mysql> insert into DemoTable1616 values(103,'David',56); mysql> insert into DemoTable1616 values(101,'Bob',89);
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1616;
这将产生以下输出-
+-----------+-------------+--------------+ | StudentId | StudentName | StudentMarks | +-----------+-------------+--------------+ | 101 | Chris | 56 | | 102 | Bob | 87 | | 103 | David | 56 | | 101 | Bob | 89 | +-----------+-------------+--------------+ 4 rows in set (0.00 sec)
这是使用逻辑AND运算符更新的查询-
mysql> update DemoTable1616 set StudentName='Adam' where StudentId=101 and StudentMarks=56; Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
mysql> select * from DemoTable1616;
这将产生以下输出-
+-----------+-------------+--------------+ | StudentId | StudentName | StudentMarks | +-----------+-------------+--------------+ | 101 | Adam | 56 | | 102 | Bob | 87 | | 103 | David | 56 | | 101 | Bob | 89 | +-----------+-------------+--------------+ 4 rows in set (0.00 sec)