title: Can I alias a select query in a multiline update in MySQL?
body: <p>I'm trying to make this MySQL code more readable:</p>
  <pre><code>UPDATE customers
      SET last_order_date = (SELECT MAX(date) FROM orders WHERE customers.customer_id = orders.customer_id),
          added_note = (SELECT note FROM orders WHERE customers.customer_id = orders.customer_id 
                       AND date = (SELECT MAX(date) FROM orders WHERE customers.customer_id = orders.customer_id));
  </code></pre>
  <p>The example code adds the date and note of the most recent order of each customer to the corresponding row in the customer table, but it has to <code>SELECT</code> the most recent order date for any given customer twice.</p>
  <p>I tried the alias syntax suggested <a href="https://stackoverflow.com/questions/16806567/alias-in-mysql-select-query">here</a>:</p>
  <pre><code>UPDATE customers
      SET last_order_date = (SELECT MAX(date) AS `maxdate` FROM orders WHERE customers.customer_id = orders.customer_id),
          added_note = (SELECT note FROM orders WHERE customers.customer_id = orders.customer_id 
                       AND date = `maxdate`);
  </code></pre>
  <p>I also tried without the <code>AS</code> keyword:</p>
  <pre><code>UPDATE customers
      SET last_order_date = (SELECT MAX(date) maxdate FROM orders WHERE customers.customer_id = orders.customer_id),
          added_note = (SELECT note FROM orders WHERE customers.customer_id = orders.customer_id 
                       AND date = maxdate);
  </code></pre>
  <p>But in neither cases the alias is recognized.</p>
  <p>Is there a way I can assign an intermediate result to a name and refer to it later?</p>