MySQL update usage, how to handle

Source: Internet
Author: User
Tags mysql update
The use of MySQL update
Can I use subqueries in UPDATE statements for MySQL?

Update score Set name = ' Harry ' where total score = (select min (total score) from score);

Why do I go wrong with this?

/*******************
CREATE TABLE IF not EXISTS score (
Study number BIGINT UNSIGNED,
Name varchar (10),
Mathematics TINYINT UNSIGNED,
English TINYINT UNSIGNED,
Physical TINYINT UNSIGNED,
Computer synthesis TINYINT UNSIGNED,
Total score int UNSIGNED
);

ensured that each field data is inserted correctly
********************/


For advice

------Solution--------------------
Try this,

Update score set ... where total score in (SELECT * FROM (select min (total score) as total from score) T)
------Solution--------------------
SQL Code
Update score Set name = ' Harry ' ORDER by total score ASC limit 1;
------Solution--------------------
MySQL Update table can not appear in the first layer of subqueries, refer to the 4 floor method to bypass the first layer of subqueries
------Solution--------------------
Try it, you know.
SQL Code
UPDATE score  SET math = (select math from (select MIN (math) as math from score) t)-4 WHERE name = ' Harry ';
  • 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.