'MYSQL Insert a spcific value to a col

I need to update a DB that has errors within it.

I have created and imported a second table with all the correct fields. This statement compares the two tables for the col that has the error in it returning all is_councilors = Y :

 SELECT users_base.first_name, users_base.is_councilor,
      users_base.email,
      users_bk2.is_councilor
    FROM users_base
    INNER JOIN users_bk2
    ON users_base.first_name=users_bk2.first_name AND users_base.email = users_bk2.email 
    WHERE users_bk2.is_councilor = 'Y'; 

My question: what is the insert/update statement to update users_base.is_councilor to a value of '1' WHERE users_bk2.is_councilor is a value of 'Y' now that i'm generating this list?



Solution 1:[1]

Try like this

UPDATE users_base ub
    INNER JOIN users_bk2 ub2
    ON ub.first_name=ub2.first_name 
    AND ub.email = ub2.email
SET ub.is_councilor = '1'
WHERE ub2.is_councilor = 'Y'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul