How can we delete multiple rows from a MySQL table?

MySQLMySQLi Database

We can use DELETE statement along with a WHERE clause, which identifies those multiple rows, to delete multiple rows from MySQL table.

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 query above will delete multiple rows because WHERE clause identify two rows having id > 2 from table ‘names’.

mysql> Select * from names;
+------+-----------+
| id   | name      |
+------+-----------+
| 1    | Rahul     |
| 2    | Gaurav    |
+------+-----------+
2 rows in set (0.00 sec)
raja
Published on 19-Feb-2018 14:35:46
Advertisements