title: How to assign a variable to select and update a field with it
body: <p>I have two columns in my table, and I am trying to update the second column with the result of first col like this. </p>
  
  <pre><code>SET @pg = (SELECT ID FROM wp_posts WHERE post_name = 'y' AND post_status = 'x' LIMIT 1)
  </code></pre>
  
  <p>Now the above query works the (SELECT ...) as in it returns an ID from the query, so I am trying to use that ID to update another column like this. </p>
  
  <pre><code>UPDATE wp_posts SET post_type = 'foo' WHERE ID = @pg; 
  </code></pre>
  
  <p>But for some reason the above does not work. </p>
  
  <p>and I get the following error. </p>
  
  <pre><code>1 queries executed, 0 success, 1 errors, 0 warnings
  
  Query: set @pg = (SELECT ID FROM wp_posts WHERE post_name = 'y' AND post_status = 'x' LIMIT 1) SELECT * ...
  
  Error Code: 1064
  You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT * FROM wp_posts WHERE id = @pg' at line 3
  
  Execution Time : 0 sec
  Transfer Time  : 0 sec
  Total Time     : 0 sec
  </code></pre>
  
  <h3>EDIT/UPDATE:</h3>
  
  <p>I am also trying to execute this staetment, which is simpler and does the same thing</p>
  
  <pre><code>UPDATE wp_posts SET post_type = 'x' WHERE ID = (SELECT ID FROM wp_posts WHERE post_name = 'y' AND post_status = 'z' LIMIT 1)
  </code></pre>
  
  <p>but for some reason, it doesn't work. </p>