2010-11-02 101 views
2

我有两个脚本,一个用于插入,另一个用于更新。MySQL更新语句错误

我的更新按钮脚本是采用了最新的插入的标识,并继续是这样的:

Update tblsurvey 
set WouldLikeToBeSeenOnSite = 'sadffas' 
and DislikedOnSite = 'asdfsadfsadf' 
and OtherNewsWebsitesRead = 'asdfsadfa' 
and LikedOnOtherNewsSites = 'asdfsadfas' 
and IPAddress = '172.16.0.123' 
and DateAnswered = current_date() 
where SurveyResponseId in (select max(SurveyResponseId) from tblsurvey); 

显然,“where”子句产生一个错误:

1093 - you cant specify target table 'tblsurvey' for update in FROM clause. 

有什么其他方式,我可以使用我正在更新的同一张表的最新插入ID?

谢谢。

回答

3

等一下。你为什么要用AND来分隔SET claus元素?它必须用逗号分隔。

1

对于子查询FROM子句和更新目标,您都不能使用相同表(在本例中为table tblsurvey)。

对于UPDATEDELETE操作,使用同一表进行更新/删除和子查询是非法的。

+0

好吧,因为我无法做任何事情,我决定只是创建另一个sp得到最后插入的ID ..谢谢无论如何。 :) – iceheaven31 2010-11-02 08:45:59