如何获取列的值并更新单个查询中的另一列?

时间:2014-01-25 16:50:54

标签: mysql

如何在执行此查询时将yes_displayed设置为1?

 select message 
 from commands 
 where whether_executed=1 
 and whether_displayed=0 
 and from_who='".$user_id."' 
 LIMIT 1

2 个答案:

答案 0 :(得分:0)

之后,您可以像这样运行更新查询

 UPDATE commands SET whether_displayed=1
 WHERE whether_executed=1 
 AND from_who='".$user_id."'

或者

 UPDATE commands 
 SET whether_displayed=1
 WHERE message IN (
 SELECT message FROM (
     SELECT message FROM commands 
     where whether_executed=1 
     and whether_displayed=0 
     and from_who='".$user_id."' 
     LIMIT 1
 ) tmp
 );

答案 1 :(得分:0)

试试这个

  UPDATE commands SET whether_displayed= '1' 
   WHERE from_who='".$user_id."' = (
          SELECT from_who
          FROM commands 
          where whether_executed=1 
          LIMIT 1
        );

此查询中的一些其他行或更改需要根据您的需要