Home  >  Article  >  Database  >  How can we delete multiple rows from MySQL table?

How can we delete multiple rows from MySQL table?

PHPz
PHPzforward
2023-09-12 09:17:121080browse

我们如何从 MySQL 表中删除多行?

We can delete multiple rows from a MySQL table using the DELETE statement and a WHERE clause that identifies these multiple rows.

Example

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)

The above query will delete multiple rows because the WHERE clause identifies two rows with id > 2 from table "names".

mysql> Select * from names;
+------+-----------+
| id   | name      |
+------+-----------+
| 1    | Rahul     |
| 2    | Gaurav    |
+------+-----------+
2 rows in set (0.00 sec)

The above is the detailed content of How can we delete multiple rows from MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete