php mysql更新限制

标签 php insert-update

我想更新 mysql 数据库,其中 directory = 0,并且只更新 5 条记录,其中值 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");

最佳答案

你的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/

相关文章:

php - 如何在codeigniter中使用连接表获取数据NO ID?

php - 如何在php中动态设置数组键

php - Laravel Homestead php-7 "php5-fpm: unrecognized service"上 vagrant up

mysql - 使用 sqlalchemy 检查行和返回 id 的存在很慢

mysql - 在数据库中输入相同名称时出现问题

mysql - 什么是删除重复主键而不是更新它们(保留最新记录)的快速查询?

php - Zend Database 不产生值(value)

php - 如何通过数组排序在mysql IN和NOT IN中获取结果

python - 当两个数据帧的列名称匹配时查找值

java - 使用 JdbcBatchItemWriter 更新重复键