CREATE TABLE dualx( x_id VARCHAR(5) NOT NULL , x_con VARCHAR(10) ) CREATE TABLE dualy( y_id VARCHAR(5) NOT NULL , y_con VARCHAR(10) ) INSERT INTO dualx VALUES (‘1‘,‘xxx‘); INSERT INTO dualx VALUES (‘2‘,‘xxx‘); INSERT INTO dualx VALUES (‘3‘,‘xxx‘); INSERT INTO dualy VALUES (‘1‘,‘111‘); INSERT INTO dualy VALUES (‘2‘,‘222‘); INSERT INTO dualy VALUES (‘3‘,‘333‘); UPDATE dualx SET (x_con) = (SELECT y.y_con FROM dualy y WHERE dualx.x_id = y.y_id) SELECT * FROM dualx; SELECT * FROM dualy; DROP TABLE dualx; DROP TABLE dualy;
UPDATE dualx SET (x_con) = (SELECT y.y_con FROM dualy y WHERE dualx.x_id = y.y_id) 其中SELECT y.y_con FROM dualy y WHERE dualx.x_id = y.y_id不能返回多行,否则报错。
时间: 2024-10-17 16:16:40