如何从 MySQL 表中删除多行?
我们可以使用 DELETE 语句和 WHERE 子句(用于标识这些多行)从 MySQL 表中删除多行。
示例
mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | | 3 | Raman | | 5 | Ram | +------+-----------+ 4 rows in set (0.00 sec) mysql> DELETE from names WHERE id > 2; Query OK, 2 rows affected (0.04 sec)
上面的查询将删除多行,因为 WHERE 子句标识了表“names”中 id > 2 的两行。
mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | +------+-----------+ 2 rows in set (0.00 sec)
广告