title: Update multiple rows from same table in mysql
body: <p>Update a single column over multiple rows depending on the data from the same table.</p>
  
  <pre><code>update table1 set status=newtime
      from (
              select
              case
              when TIME_FORMAT( TIMEDIFF( ADDTIME( time_val, '120:00:00' ), NOW() ), '%Hh %im %ss')&lt;0 then '4'
              else '0'
              end as newtime,
              id as new_id
              FROM table1
              where id2='2'
              and status='0'
      )
  where id=new_id
  </code></pre>
  
  <p>This is my query. Thanks in advance.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This is an alternate query to achieve this. But it also gives me an error</p>
  
  <pre><code>update table1 set status=
          (select
          case when timeleft&lt;0 then '4' else '0' end as something,
          new_id
          from
              (
                  select
                  TIME_FORMAT( TIMEDIFF( ADDTIME( time_val, '120:00:00' ), NOW() ), '%Hh %im %ss') as newtime,
                  id as new_id
                  FROM
                  table1 
                  where id2='2' and
                  status='0'
              )
          }
      where id=new_id
  </code></pre>
  
  <blockquote>
    <blockquote>
      <blockquote>
        <p>"#1248 - Every derived table must have its own alias".</p>
      </blockquote>
    </blockquote>
  </blockquote>
  
  <p>I cannot use alias as I am fetching two columns from the query. Any help would be great.</p>