title: Retrieve data with its relations from a database
body: <p>I am struggling to get data I need from my database.  So my structure is pretty straight forward, I have a questions table</p>
  <pre><code>quiz_question
      id (PK)
      question (text)
      type (text)
  
  quiz_answer
      id (PK)
      question_id (FK)
      answer (text)
  </code></pre>
  <p>So my database may look a bit like so for a question and answer.</p>
  <pre><code>quiz_question
  
  id  |   question               |  type
  ----------------------------------------
  1   |   What is your gender    |  radio
  
  
  quiz_answer 
  
  id  |   question_id   |  answer
  ------------------------------------
  1   |   1             |  Male
  ------------------------------------
  2   |   1             |  Female
  ------------------------------------
  3   |   1             |  Non-binary
  </code></pre>
  <p>So what I am trying to do is build up some JSON to return the questions with their associated answers, something like the following.</p>
  <pre><code>{
      questions [{
          id: 1,
          question: 'What is your gender',
          type: 'radio',
          answers: [
              {
                  'Male'
              },
              {
                  'Female'
              },
              {
                  'Non-binary'
              }
          ]
        }...
      ]
  }
  </code></pre>
  <p>I am trying to form an SQL query but getting a bit lost, currently I have</p>
  <pre><code>select quiz_question.question, quiz_question.helptext,
          quiz_question.imageurl, quiz_question.questiontype 
  FROM quiz_question 
      INNER JOIN quiz_answer on quiz_question.id = quiz_answer.questionId;
  </code></pre>
  <p>However, that seems to return a strange dataset.  So how can I query my database to retrieve the questions with their answers?</p>
  <p>Thanks</p>