search

Home  >  Q&A  >  body text

Is there any statement in mysql that can directly update the first ten items of sorted data?

Excuse me, is there any SQL that can directly sort the current table by score, and then update a field in the top ten?

迷茫迷茫2823 days ago717

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-19 10:09:15

    That is, the IN/ALL/ANY/SOME subquery using the LIMIT clause is not supported, as long as you add another layer, such as:

    UPDATE table SET name='zhangsan' WHERE id IN
    (SELECT t.id FROM (SELECT id FROM table LIMIT 10) AS t) 

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:09:15

    update table set name='zhangsan' where id in (
     select id from table order by sorce desc limit 10
    )
    
    //可以做到,子查询就完事

    reply
    0
  • Cancelreply