简体   繁体   中英

Insert column from another table while matching emails in both tables

I'm trying to insert phone number field from orders table into users table, while matching orders.Email field = users.Email field.

This is what I have so far but the WHERE clause is not working:

INSERT INTO users (Phone)  
SELECT Billing_Phone
  FROM orders
WHERE users.Email = orders.Email

To modify rows, you use UPDATE , not INSERT .

UPDATE users AS u
JOIN orders AS o ON u.Email = o.Email
SET u.Phone = o.Billing_Phone

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