首页 > 文章列表 > 我们如何从MySQL表中删除单行数据?

我们如何从MySQL表中删除单行数据?

488 2023-08-27

我们可以使用DELETE语句和WHERE子句,来删除MySQL表中的特定行。

示例

mysql> Select * from names;
+------+-----------+
| id   | name      |
+------+-----------+
| 1    | Rahul     |
| 2    | Gaurav    |
| 3    | Raman     |
| 4    | Aarav     |
| 5    | Ram       |
+------+-----------+
5 rows in set (0.00 sec)

mysql> DELETE from names where id = 4;
Query OK, 1 row affected (0.07 sec)

上面的查询将从表 ‘names’ 中删除一个id = 4的行。

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