如何从 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 子句可识别 table ‘names’ 中 id > 2 的两行。
mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | +------+-----------+ 2 rows in set (0.00 sec)
广告