2

我想更新 mysql 数据库, where directory = 0,然后5 of records将哪个值更新0art.

解释:

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");
4

2 回答 2

6

你的语法很好。

我将添加一个 order by 子句(可以肯定)

ORDER BY `Id`

查询

UPDATE articles SET directory = 'art' WHERE directory ='0' ORDER BY id LIMIT 5
于 2011-04-03T10:06:20.473 回答
1

你的查询对我来说似乎没有错。

但请注意,您可能还想指定一个order by子句,以确定哪些是五个“第一”项:

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


仅供参考:更新语法

于 2011-04-03T10:06:58.923 回答