MySQL:1093错误解决办法

阅读更多
UPDATE posts SET SpareFlag=0 WHERE Id IN(
	SELECT Id FROM posts WHERE CloseFlag=0 AND LockFlag=0 GROUP BY PosterUid HAVING COUNT(PosterUid)=1
);

 上面这样的写法,数据库会提示1093错误;正确写法如下:

UPDATE posts SET SpareFlag=0 WHERE Id IN(
  SELECT b.Id FROM (SELECT Id FROM posts WHERE CloseFlag=0 AND LockFlag=0 GROUP BY PosterUid HAVING COUNT(PosterUid)=1) AS b
);

 即,为查询条件建个临时表,这样就解决问题了。

你可能感兴趣的:(MySQL,1093,update,select,in)