通过在 WHERE 子句中使用 AND 从 MySQL 表中删除特定记录
MySQL AND 用于 WHERE 以通过多个条件过滤来抓取记录。我们首先创建一个表 -
mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.70 sec)
通过使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable values(101,'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(102,'David'); Query OK, 1 row affected (0.51 sec) mysql> insert into DemoTable values(103,'Bob'); Query OK, 1 row affected (0.14 sec)
使用 select 语句从表中显示所有记录 -
mysql> select * from DemoTable;
这将产生以下输出 -
+------+-------+ | Id | Name | +------+-------+ | 101 | Chris | | 102 | David | | 103 | Bob | +------+-------+ 3 rows in set (0.00 sec)
这是删除记录的查询 -
mysql> delete from DemoTable where Id=102 and Name='David'; Query OK, 1 row affected (0.20 sec)
让我们再次检查表记录 -
mysql> select * from DemoTable;
这将产生以下输出 -
+------+-------+ | Id | Name | +------+-------+ | 101 | Chris | | 103 | Bob | +------+-------+ 2 rows in set (0.00 sec)
广告