一个语句大概如下
update table set ... where 列名 in (select ... limit 0,20)查了一下,mysql好像是不支持在子查询里头有limit的,可是我是在想不出方法来绕过去,后面的子查询一定要只有20条记录的我也想过先把子查询 select ... limit 0,20执行一下,把结果存在数组里头,可是不知道具体怎么实现,还能用in 语法么?请高手赐教
update table set ... where 列名 in (select ... limit 0,20)查了一下,mysql好像是不支持在子查询里头有limit的,可是我是在想不出方法来绕过去,后面的子查询一定要只有20条记录的我也想过先把子查询 select ... limit 0,20执行一下,把结果存在数组里头,可是不知道具体怎么实现,还能用in 语法么?请高手赐教
解决方案 »
- mysql如何查询表?
- 如何设置要求开发者的java程序不许链接,只能查看数据。
- 请问怎样才能将一个表的数据导入到另一个表里,两个表的结构不一样
- 新安装MySQL 5.0.37里边无法录入中文,数字与英文字母都正确,这个到底怎么弄呀?
- 中文排序得问题!请各位大虾帮忙解决!!
- MySQL 循环遍历表 更改表结构
- Mysql 安装的时候出错求助!!
- ??=====新手刚开始学习数据库读什么书好呢?=======??
- Decimal类型的字段为什么不能为Null?
- 求大牛们帮个忙!感激不尽!急!!powerdesigner生成 的sql脚本错误
- 求sql语句
- mysql大量数据查询出错,少量就没事,怎么回事呢?
而是UPDATE语句不支持LIMIT
update a,b set .... where a.id=b.id limit b
[order by xxx ]
limit 0,20
UPDATE 支持LIMIT 语句不是SELECT语句中的LIMIT。
而是它特有的LIMIT
只能限制多少行。CREATE TABLE `a` (
`aid` int(11) NOT NULL,
`title` varchar(1000) NOT NULL,
PRIMARY KEY (`aid`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312
==========select * from a;query result(10 records)
aid title
1 666
2 yyy
3 666
4 343
5 (NU
6 343
7 fgh
8 676
9 yyh
10 rtrt -----------update a set title = 'csdn' order by aid desc limit 2;
(2 row(s)affected)
(0 ms taken)
select * from a;
query result(10 records)
aid title
1 666
2 yyy
3 666
4 343
5 (NU
6 343
7 fgh
8 676
9 csdn
10 csdn
----update a set title = 'csdn' order by aid asc limit 2 ;
select * from a;
(2 row(s)affected)
(0 ms taken)(10 row(s)returned)
(0 ms taken)
query result(10 records)
aid title
1 csdn
2 csdn
3 666
4 343
5 (NU
6 343
7 fgh
8 676
9 csdn
10 csdn
Error Code : 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '6' at line 1
(0 ms taken)
应该把字查询改为临时表格a,
update table set ... where 列名 in (select ... from ( select ... limit 0,20) a)把你的字查询语句再次做一个表格,这样他在a表,而不是in字查询里出现limit