我们如何从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;
上面的查询将删除多行,因为WHERE子句从表'names'中识别出id>2的两行。
mysql> Select * from names; +------+-----------+ | id | name | +------+-----------+ | 1 | Rahul | | 2 | Gaurav | +------+-----------+ 2 rows in set (0.00 sec)