SQLの質問。私はtable_idである適切なparent_idに対してsystem_idをpartent_idとして配置します。だから私はこれをしようとしていたが、いくつかのエラーを取得しています:同じテーブルの値を持つテーブルを更新します。
update justmarket.companies e, (Select DISTINCT company_id from justmarket.companies where parent_id = system_id) c
set e.parent_id = c.company_id
where e.company_id = c.company_id
はエラーを終了:
Error Static analysis:
6 errors were found during analysis.
An expression was expected. (near "(" at position 31) Unexpected token. (near "(" at position 31) A new statement was found, but no delimiter between it and the previous one. (near "Select" at position 32) Unexpected token. (near ")" at position 112) Unexpected token. (near "c" at position 114) A new statement was found, but no delimiter between it and the previous one. (near "set" at position 117) SQL query: Documentation
update justmarket.companies e, (Select DISTINCT company_id from justmarket.companies where parent_id = system_id) c set e.parent_id = c.company_id where e.company_id = c.company_id
MySQL said: Documentation
1205 - Lock wait timeout exceeded; try restarting transaction
表: のcompany_id COMPANY_NAME SYSTEM_ID PARENT_ID 1名1 55121 0 2 Name2は52211 55121 3 NAME3 55444 55121
私が探しているもの company_id company_name system_id parent_id 1名1 55121 0 2 Name2は52211 1 3 NAME3 55444 1
サンプルデータと望ましい結果が実際に役立ちます。 –
私は最初のエラーはPhpMyAdminのバグだと思う、複数テーブルの 'UPDATE'構文を理解していない。 – Barmar
そのエラーを取得する別のクエリについては、https://stackoverflow.com/questions/35608945/mysql-replace-statement-incorrect-a-new-statement-was-found-but-no-delimiterを参照してください。 – Barmar