我想更新表中某行中的某几列,更新完后,要得到这行的所有列,如何用一个sql 语句实现。谢谢create table role
(
id int not null auto_increment,
roleid int,
silver  int,
gold int,
primary key (id)
)update role set gold=gold+100 where roleid=1;
select * from  role where roleid=1;
以上2个语句合并

解决方案 »

  1.   

    第一,二者没关联性,故而没法直接相联;
    第二,注意语句规范,手册中说明,请使用大写.类同这样的可以合并
    update role set gold=gold+100 where roleid = (SELECT wcid FROM WC WHERE roleid = '1');
      

  2.   

    顶2楼 ACMAIN_CHM,这么久了还看你在,谢谢你以前帮我解决好多mysql问题。赞一个!
      

  3.   

    无法合并,建议用存储过程:
    create procedure updateAndBack(in cId int)
    begin
        set @mySql = concat('update role set gold=gold+100 where roleid=',cId);
        prepare stmt from @mySql;
        execute stmt;    set @mySql = concat('select * from role where roleid=',cId);
        prepare stmt from @mySql;
        execute stmt;
    end调用时call updateAndBack(1)即可。