Can subqueries be used in MySQL Update statements for MySQL update? & Nbsp; updatescoreset name = 'Wang Wu' where total score = (selectmin (total score) fromscore); why am I using this error? /******************** Use of CREATE MySQL Update
Can subqueries be used in MySQL update statements?
Update score set name = 'Wang Wu' where total score = (select min (total score) from score );
Why am I wrong when I use this?
/*******************
Create table if not exists score (
Student id bigint unsigned,
Name varchar (10 ),
Mathematical tinyint unsigned,
Tinyint unsigned,
Physical tinyint unsigned,
Computer integrated tinyint unsigned,
Total int UNSIGNED
);
The data of each field is correctly inserted.
********************/
Ask for advice!
------ Solution --------------------
Try this way,
Update score set ...... Where total score in (SELECT * FROM (SELECT min (total score) AS total score FROM score) t)
------ Solution --------------------
SQL code
Update score set name = 'Wang 5' order by Total asc limit 1;
------ Solution --------------------
The update table in mysql cannot appear in the subquery at the first layer. refer to the method on the fourth floor to allow the table to bypass the first layer of subquery.
------ Solution --------------------
I don't know if I try it.
SQL code
UPDATE score SET Mathematics = (SELECT mathematics FROM (select min (mathematics) AS mathematics FROM score) t)-4 WHERE name = 'Wang Wu ';