我想更新 mysql 数据库,其中 directory = 0
,并且只更新 5 条记录
,其中值 0
为 art
。
解释:
id | directory
1 | fashion
2 | 0 //update here into 'art'
3 | travel
4 | fashion
5 | 0 //update here into 'art'
6 | 0 //update here into 'art'
7 | travel
8 | 0 //update here into 'art'
9 | 0 //update here into 'art'
10 | 0 //this is 6th record, do not update, leave the value as '0'.
11 | fashion
这个更新码对吗?谢谢。
mysql_query("UPDATE articles SET directory = 'art' WHERE directory ='0' LIMIT 5");
最佳答案
你的syntax很好。
我将添加一个 order by 子句(确定)
ORDER BY `Id`
查询
UPDATE articles SET directory = 'art' WHERE directory ='0' ORDER BY id LIMIT 5
关于php mysql更新限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5528885/