How to deal with the use of MySQL Update

Source: Internet
Author: User
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 ';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.