DELETE语句

1、

不能先select出同一表中的某些值,再update这个表(在同一语句中)

DELETE FROM Person WHERE id NOT IN 
	( SELECT MIN(id) as id 
		FROM Person GROUP BY email )

所以要通过子表(派生表)

 DELETE FROM Person WHERE id NOT IN
 	 ( select *from (SELECT MIN(id) as id 
 	 FROM Person GROUP BY email ) as a )

**ps:**每个派生表必须有自己的别名,所以给查出的子表一个别名

2、

如果在delete时使用了别名,就要在delete与from中加入别名

delete p1 from person p1,perosn p2 
where p1.id = p2.id;
上一篇:leetcode 力扣数据库题175. 组合两个表,左外连接


下一篇:C++提高编程 3 STL常用容器 -set/multiset容器