请问在mysql中怎么更新前N条记录?

解决方案 »

  1.   

    ?你是什么意思啊?update 表 set 属性=value where 条件;符合条件的记录都会被更新掉拉,算不算N条记录?
      

  2.   

    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   
    这是人家以前回答的,你看吧