Two tables, if you want the value of the bname field in B to equal the aname value of the corresponding id in the A table

A friend asked me a question about a database, as follows

Two tables, if you want the value of the bname field in B to equal the aname value of the corresponding id in the A table

Table A

id aname
1 1
2 2
3 3

Table B

id bname
1  
2  
3  

Please write the correct sql statement.

The answer I gave is as follows, the pro test can pass

UPDATE B LEFT JOIN A ON B.`id` = A.`id` SET B.`bname` = A.`aname`;

Guess you like

Origin blog.csdn.net/qq_26896085/article/details/105041015