【MYSQL】delete from

  • delete from 单表语法
DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name  
[WHERE where_definition]  
[ORDER BY ...]  
[LIMIT row_count] 
  • delete from 多表语法
DELETE [LOW_PRIORITY] [QUICK] [IGNORE]  
tbl_name[.*] [, tbl_name[.*] ...]  
FROM table_references  
[WHERE where_definition] 

或

DELETE [LOW_PRIORITY] [QUICK] [IGNORE]  
FROM tbl_name[.*] [, tbl_name[.*] ...]  
USING table_references  
[WHERE where_definition] 

delete from  简单示例

mysql> select * from ns;
+-----+-------+------------+
| uid | uname | udate2     |
+-----+-------+------------+
|   2 | alex  | 1989-01-10 |
|   7 | uuuu  | 0000-00-00 |
|   8 | kkkk  | 0000-00-00 |
|   9 | leb   | 0000-00-00 |
|  10 | uuuu  | 2000-11-22 |
|  11 | uuuu  | 1876-11-22 |
|  12 | uuuu  | 1876-11-22 |
|  13 | uuuu  | 1223-12-12 |
+-----+-------+------------+
8 rows in set (0.00 sec)

mysql> delete from ns where uid=2;
Query OK, 1 row affected (0.00 sec)

mysql> select * from ns;
+-----+-------+------------+
| uid | uname | udate2     |
+-----+-------+------------+
|   7 | uuuu  | 0000-00-00 |
|   8 | kkkk  | 0000-00-00 |
|   9 | leb   | 0000-00-00 |
|  10 | uuuu  | 2000-11-22 |
|  11 | uuuu  | 1876-11-22 |
|  12 | uuuu  | 1876-11-22 |
|  13 | uuuu  | 1223-12-12 |
+-----+-------+------------+
7 rows in set (0.00 sec)

mysql> delete from ns where uname='leb';
Query OK, 1 row affected (0.00 sec)

mysql> select * from ns;
+-----+-------+------------+
| uid | uname | udate2     |
+-----+-------+------------+
|   7 | uuuu  | 0000-00-00 |
|   8 | kkkk  | 0000-00-00 |
|  10 | uuuu  | 2000-11-22 |
|  11 | uuuu  | 1876-11-22 |
|  12 | uuuu  | 1876-11-22 |
|  13 | uuuu  | 1223-12-12 |
+-----+-------+------------+
6 rows in set (0.00 sec)

mysql> delete from ns where uid in (7,8,9);
Query OK, 2 rows affected (0.01 sec)

mysql> select * from ns;
+-----+-------+------------+
| uid | uname | udate2     |
+-----+-------+------------+
|  10 | uuuu  | 2000-11-22 |
|  11 | uuuu  | 1876-11-22 |
|  12 | uuuu  | 1876-11-22 |
|  13 | uuuu  | 1223-12-12 |
+-----+-------+------------+
4 rows in set (0.00 sec)

mysql> delete from ns;
Query OK, 4 rows affected (0.01 sec)

mysql> select * from ns;
Empty set (0.00 sec)
  •  delete from  与 select 子查询
posted @ 2016-11-10 10:39  AlexBai326  阅读(2219)  评论(0编辑  收藏  举报