title: Mysql update rows dynamically based on column input
body: <p>I have the following issue. I have a table called <code>titles</code> with the following structure:</p>
  
  <pre><code>id int(10),
  name varchar(100),
  </code></pre>
  
  <p>At some point later we added a new column called <code>modified_name</code>. It is defined as the same as <code>name</code> except that it is lower case and has all of the spaces replaced with a <code>-</code>. We added this column and so we needed to now get the right modified name value into each record of that column. To do this we wrote a PHP script that handled that by loading in values from the database and processing them, but that is highly inefficient. Is it possible to write a single <code>UPDATE</code> query that would add the correct value to each record in the <code>titles</code> table. I can think of ways to do this with a stored procedure and a while loop there in, but I want to know if something more efficient is possible. It there any way to achieve something like the following:</p>
  
  <pre><code>UPDATE `titles` 
      SET 
  `modified_name` = LOWER(REPLACE(SELECT `name` FROM `titles` WHERE id = PRESENT_VALUE), ' ', '-');
  </code></pre>
  
  <p>The goal being to SET the <code>modified_title</code> column of every record in the <code>titles</code> table to a unique value that results from that record's <code>name</code> column as followed:</p>
  
  <pre><code># Before modification update query
  name = "Hello Goodbye" 
  modified_name = ""    
  
  # After modification update
  name = "Hello Goodbye" 
  modified_name = "hello-goodbye"
  </code></pre>
  
  <p>Thank you for your help, any advice on how best to do this would be appreciated.     </p>