---
title: "MYSQL使用Limit限定更新行数"
author: "essen"
date: "2013-04-16T11:34:02Z"
tags: []
categories: ["数据库"]
slug: "mysql-limit"
draft: false
lastmod: "2013-04-16T11:37:15Z"
id: 1848131
url: "https://essen.iteye.com/blog/1848131"
---

**上下文：想要修改config表，将其中**5607行的is\_ok改为true。

 

想通过下面的sql语句实现

```
UPDATE channel_config set is_adam_pub=1 where channel_id in (select channel_id from channel_config limit 5607);
```

 

发现Mysql不能支持子句使用Limit，数据库会报错

This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery'

 

网上找一方法，可以支持子串使用Limit

```
UPDATE channel_config set is_adam_pub=1 where channel_id in (select t.channel_id from (select channel_id from channel_config limit 5607)as t);
```

这样处理虽然能达到效果，但是执行很慢，用了15.815ms

 

转念一想，update是不是也有limit用法

```
UPDATE channel_config set is_adam_pub=1 LIMIT 5607;
```

 

 发现竟然成功了，而且就用了0.102ms

 

--end--