从MySQL表中删除WHERE列等于值AND column2等于value2吗?
让我们首先创建一个表-
mysql> create table DemoTable722 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable722(StudentName,StudentAge) values('Chris Brown',23) ; mysql> insert into DemoTable722(StudentName,StudentAge) values('John Smith',21); mysql> insert into DemoTable722(StudentName,StudentAge) values('David Miller',22); mysql> insert into DemoTable722(StudentName,StudentAge) values('Adam Smith',20); mysql> insert into DemoTable722(StudentName,StudentAge) values('Carol Taylor',24);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable722;
这将产生以下输出-
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 23 | | 2 | John Smith | 21 | | 3 | David Miller | 22 | | 4 | Adam Smith | 20 | | 5 | Carol Taylor | 24 | +-----------+--------------+------------+ 5 rows in set (0.00 sec)
以下是要从MySQL表中删除的查询WHERE列等于值ANDcolumn2等于value2-
mysql> delete from DemoTable722 where StudentId=3 and StudentName='David Miller';
让我们再次检查表记录-
mysql> select *from DemoTable722;
这将产生以下输出-
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 23 | | 2 | John Smith | 21 | | 4 | Adam Smith | 20 | | 5 | Carol Taylor | 24 | +-----------+--------------+------------+ 4 rows in set (0.00 sec)