title: SQL multiple rows as columns with out using PL/SQL
body: <p>I have 3 tables</p>
  
  <ul>
  <li><code>questions (q_id, q_text)</code></li>
  <li><code>answers (a_id, a_text, q_id)</code></li>
  <li><code>correct_answers (q_id, a_id)</code></li>
  </ul>
  
  <p>answers table can have minimum of 1 and maximum of 4 values for each question</p>
  
  <p>I need a pure SQL query (joins or sub query) to have following table as result</p>
  
  <pre><code>result (q_id, q_text, option1, option2, option3, option4, correct)
  </code></pre>
  
  <p><code>option1</code>, <code>option2</code>, <code>option3</code>, <code>option4</code> all belong to answers tables and can be <code>null</code>, <code>correct</code> belong to <code>correct_answers</code> table</p>
  
  <p>Questions:</p>
  
  <pre><code>q_id  q_text
  2     Capital of Pakistan is
  3     Karachi is in africa
  5     New dehli is _____ of india
  </code></pre>
  
  <p>Answers:</p>
  
  <pre><code>a_id  a_text     q_id
  1     Lahore     2
  2     Islamabad  2
  3     Karachi    2
  4     Quetta     2
  5     True       3
  6     False      3
  7     Capital    5
  </code></pre>
  
  <p>Correct_answer:</p>
  
  <pre><code>q_id  a_id
  2     2
  3     6
  5     7
  </code></pre>
  
  <p>result of query:</p>
  
  <pre><code>q_id  q_text                       option_1   option_2   option_3  option_4 correct
  2     Capital of Pakistan is       Lahore     Islamabad  Karachi   Quetta   Islamabad
  3     Karachi is in africa         True       False      null      null     False
  5     New dehli is _____ of india  Capital    Null       Null      Null     Capital
  </code></pre>