title: MySQL: How to insert multiple rows into one table for each id of another query?
body: <p>I have a key-value table and I need to insert multiple rows for each selected <code>id</code> from another table.</p>
  
  <ol>
  <li><p>I get the user id:</p>
  
  <pre><code>SELECT @id := id FROM user WHERE email = 'my@email.com';
  </code></pre></li>
  <li><p>I get the ids of things by user id:</p>
  
  <pre><code>SELECT @things := id FROM `things` WHERE `owner_id` = @id;
  </code></pre></li>
  <li><p>Now I need to insert multiple values into key-value table for each <code>@things</code>. And problem here is that I cannot use a select subquery, because I need to insert inline values, like:</p>
  
  <pre><code>INSERT INTO key_value (key, value)
  VALUES (
      @things, 'CUSTOM VALUE 1'
  ),
  VALUES (
      @things, 'CUSTOM VALUE 2'
  );
  </code></pre></li>
  </ol>
  
  <p>BUT, it does not work. The last query is obviously wrong. Any help would be much appreciated.</p>
  
  <hr>
  
  <h3>EDIT:</h3>
  
  <p>Looks like I need multiple queries to do that:</p>
  
  <pre><code>SELECT @id := id FROM user WHERE email = 'startour@netron.no';
  
  INSERT INTO key_value (`key`, `value`)
  (
      SELECT id, 'CUSTOM_VALUE_1'
      FROM `things`
      WHERE `owner_id` = @id
  );
  
  INSERT INTO key_value (`key`, `value`)
  (
      SELECT id, 'CUSTOM_VALUE_2'
      FROM `things`
      WHERE `owner_id` = @id
  );
  </code></pre>