简体   繁体   中英

Update a large mysql table with data from another table

I have two tables 'Cast' and 'Roles'. Table 'Cast' fields are Id, castName, castID, roleId. Fields of table 'Roles' are Id, castId, role_Id

I want to update role_Id in table 'Roles' where it is null in this table and is equal to '1' in table 'Cast'.

This is what I wrote:

UPDATE Roles
INNER JOIN Cast on (Cast.castID = Roles.castId)
SET Roles.role_Id = '2'
WHERE Roles.role_Id IS NULL AND Cast.roleId = '1';

Could someone help me to understand what is the problem with this query and how can I update the table 'Roles'?

I puted Cast.roleId = '1' condition at on clause

UPDATE Roles
INNER JOIN Cast on 
Cast.castID = Roles.castId  AND Cast.roleId = '1'
SET Roles.role_Id = '2'
WHERE Roles.role_Id IS NULL;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM