我想更新 mysql 数据库, where directory = 0,然后将5 of records哪个值更新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
Run Code Online (Sandbox Code Playgroud)
这个更新代码对吗?谢谢。
mysql_query("UPDATE articles SET directory = 'art' WHERE directory ='0' LIMIT 5");
Run Code Online (Sandbox Code Playgroud)
你的语法很好。
我将添加一个 order by 子句(可以肯定)
ORDER BY `Id`
Run Code Online (Sandbox Code Playgroud)
查询
UPDATE articles SET directory = 'art' WHERE directory ='0' ORDER BY id LIMIT 5
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6243 次 |
| 最近记录: |