错误代码:1093表'交易'被指定两次,两者都作为'更新'的目标。并作为单独的数据来源

时间:2017-03-24 10:25:09

标签: mysql sql

请帮忙......

UPDATE transactions SET `tr_code` = 
(SELECT CONCAT(SUBSTRING_INDEX(tr_code,  '-', 
(LENGTH(tran.tr_code) - LENGTH( REPLACE(tran.tr_code, '-', '' ) ) ) ), '-' , tran.id) FROM transactions tran
WHERE tran.id = 710) WHERE id = 710;

1 个答案:

答案 0 :(得分:0)

您根本不需要子查询:

UPDATE transactions
    SET `tr_code` = CONCAT(SUBSTRING_INDEX(tr_code,  '-', 
                                           LENGTH(tr_code) - LENGTH(REPLACE(tr_code, '-', '' ))
                                          ), '-' , id
                          ) 
    WHERE id = 710;