简体   繁体   中英

Update table with values from another table - mysql

I have an account and customer tables which can be linked by customer col and get the date col to the account table.

account table :

在此处输入图像描述

customer table :

在此处输入图像描述

final table :

在此处输入图像描述

If I use the below query, I am getting following error

ERROR: more than one row returned by a subquery used as an expression

What am I doing wrong?

UPDATE account
SET date = (
SELECT date
FROM customer
WHERE customer.customer = account.customer
);

Consider the update... join... set syntax:

update account a
inner join customer c on a.customer = c.custom
set a.date = c.date

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