php mysql 更新限制

发布于 2024-10-29 20:57:48 字数 674 浏览 5 评论 0原文

我想更新 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");

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

for explain:

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

Is this update code right? thanks.

mysql_query("UPDATE articles SET directory = 'art' WHERE directory ='0' LIMIT 5");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

吃兔兔 2024-11-05 20:57:48

你的 语法 没问题。

我将添加一个 order by 子句(当然)

ORDER BY `Id`

来查询

UPDATE articles SET directory = 'art' WHERE directory ='0' ORDER BY id LIMIT 5

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
入画浅相思 2024-11-05 20:57:48

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

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

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

只是作为参考:更新语法

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文