一个语句大概如下
update table set ... where 列名 in (select ... limit 0,20)查了一下,mysql好像是不支持在子查询里头有limit的,可是我是在想不出方法来绕过去,后面的子查询一定要只有20条记录的我也想过先把子查询 select ... limit 0,20执行一下,把结果存在数组里头,可是不知道具体怎么实现,还能用in 语法么?请高手赐教

解决方案 »

  1.   

    不是子查询不支持LIMIT
    而是UPDATE语句不支持LIMIT
      

  2.   

    这样可以么
    update a,b set .... where a.id=b.id limit b
      

  3.   

    update 支持 limit 语句update table set ... 
    [order by xxx ]
    limit 0,20
      

  4.   

    LS的。
    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 
      

  5.   

    update a set title = 'csdn' order by aid asc limit 2,6 ;
    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)
      

  6.   


    应该把字查询改为临时表格a,
    update table set ... where 列名 in (select ... from (   select ... limit 0,20) a)把你的字查询语句再次做一个表格,这样他在a表,而不是in字查询里出现limit