`

You can't specify target table 't' for update in FROM clause

 
阅读更多

You can't specify target table 't' for update in FROM clause

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

下边这个不管用

update sy_subscribe t , sy_subscribe t1 set  t.source_keyword= t1.source_id , t.source_id = t1.source_keyword ,t.unique_id = CONCAT(t1.source_id,'_',t1.source_keyword)
where t.subscribe_id = t1.subscribe_id and t.subscribe_id in (
select subscribe_id from sy_subscribe where  length(source_keyword)=CHARACTER_LENGTH(source_keyword)  and length(source_keyword)=32)
)

下边这个才能用。

update sy_subscribe t , sy_subscribe t1 set  t.source_keyword= t1.source_id , t.source_id = t1.source_keyword ,t.unique_id = CONCAT(t1.source_id,'_',t1.source_keyword)
where t.subscribe_id = t1.subscribe_id and t.subscribe_id in (
select t.subscribe_id from (select subscribe_id from sy_subscribe where  length(source_keyword)=CHARACTER_LENGTH(source_keyword)  and length(source_keyword)=32) t
)
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics