php mysql update limit

后端 未结 2 1675
失恋的感觉
失恋的感觉 2021-01-23 20:57

I want to update mysql database, where directory = 0, and just update 5 of records which value 0 to art.

for explain:

相关标签:
2条回答
  • 2021-01-23 21:27

    Your query doesn't seem wrong to me.

    But note that you might also want to specify an order by clause, to be sure which are the five "first" items :

    update articles
    set directory = 'art'
    where directory = '0'
    order by id
    limit 5
    


    Just as a reference : UPDATE Syntax

    0 讨论(0)
  • 2021-01-23 21:42

    your syntax is fine.

    i will add an order by clause (to be sure)

    ORDER BY `Id`
    

    to query

    UPDATE articles SET directory = 'art' WHERE directory ='0' ORDER BY id LIMIT 5
    
    0 讨论(0)
提交回复
热议问题