title: Adding primary key as a part of INSERT INTO table VALUES query
body: <p>Just for demonstration purposes. I have two tables &quot;quiz&quot; and &quot;question&quot;.</p>
  <p>The <strong>quiz table</strong> contains the following columns</p>
  <ul>
  <li><p>quiz_id (PK)</p>
  </li>
  <li><p>quiz_title</p>
  </li>
  </ul>
  <p>The <strong>question table</strong> contains the following columns</p>
  <ul>
  <li>question_id (PK)</li>
  <li>quiz_ID (FK)</li>
  <li>question_text</li>
  </ul>
  <p>I am trying to insert the question text into &quot;question_text&quot; in the question table.</p>
  <p>I can successfully retrieve the latest quiz_id and insert it into the question table.</p>
  <pre><code>INSERT INTO question (quiz_id) SELECT max(quiz_id) FROM quiz        
  </code></pre>
  <p>But I also need to add the question text. I tried this:</p>
  <pre><code>INSERT INTO question (question_text) VALUES (&quot;question_text_sample&quot;)
  </code></pre>
  <p>But I am getting an error because the FK info (quiz_id) is not provided in the query.</p>
  <p>I would like to combine the queries above but I can't figure out a working solution.</p>
  <p>I tried the following:</p>
  <pre><code>INSERT INTO quiz (quiz_title) values (&quot;quiz_title_sample&quot;)
  INSERT INTO question (quiz_id, question_text) VALUES (LAST_INSERT_ID(), &quot;question_text&quot;)
  </code></pre>
  <p>another try:</p>
  <pre><code>INSERT INTO question (quiz_id, question_text) VALUES (SELECT max(quiz_id) FROM quiz , &quot;question_text_sample&quot;)
  </code></pre>