MySQL更新语句错误
我有两个脚本,一个用于插入,另一个用于更新。
我的更新按钮脚本正在使用最新插入的 ID,并且继续如下所示:
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 ?
谢谢。
I have two scripts, one for the Insert, and another for Update.
My update button script is using the latest inserted Id, and goes on something like this:
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);
Apparently, the "where" clause generates an error:
1093 - you cant specify target table 'tblsurvey' for update in FROM clause.
Is there any other way in which i could use the latest inserted ID of the same table i am updating?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
等一下。为什么使用 AND 来分隔 SET 子句元素?必须以逗号分隔。
wait a second. why are you using AND to delimit SET claus elements? it must be comma separated.
您不能对子查询 FROM 子句和更新目标使用同一个表(在本例中为表 tblsurvey)。
使用同一个表进行更新/删除以及子查询进行 UPDATE 和 DELETE 操作是非法的。
you cannot use the same table (in this case, table tblsurvey) for both the subquery FROM clause and the update target.
Its illegal to use same table for updating/deleting and subquery for
UPDATE
andDELETE
operations.