从 MySQL 表中删除其中列等于值且列 2 等于值 2?
mysqlmysqli database更新于 2025/10/4 5:00:17
首先我们创建一个表 −
mysql> create table DemoTable722 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (1.84 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable722(StudentName,StudentAge) values('Chris Brown',23) ;
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable722(StudentName,StudentAge) values('John Smith',21);
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable722(StudentName,StudentAge) values('David Miller',22);
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable722(StudentName,StudentAge) values('Adam Smith',20);
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable722(StudentName,StudentAge) values('Carol Taylor',24);
Query OK, 1 row affected (0.39 sec)
使用 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 表中删除的查询,其中列等于值 AND 列 2 等于值 2 −
mysql> delete from DemoTable722 where StudentId=3 and StudentName='David Miller'; Query OK, 1 row affected (0.21 sec)
让我们再次检查表记录 −
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)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

