title: MySQL Random Limit Select with table join
body: <p>I have a simple database (see image) and I'd like to retrieve 10 questions randomly with all their answers (between 2-4 answers per question). I've tried multiple queries but I can't seem to get it right.</p>
  
  <p>Things I've tried:</p>
  
  <pre><code>SELECT qa.Answerid,qa.Questionid
  FROM question_answer as qa
  JOIN (SELECT q.Questionid FROM question q ORDER BY rand() LIMIT 10)
  WHERE qa.Questionid = q.Questionid
  
  select *
  From question q,question_answer qa,answer a 
  where qa.Questionid=q.Questionid and qa.Answerid=a.Answerid
  ORDER BY rand() LIMIT 10
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/P7v6x.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P7v6x.png" alt="enter image description here"></a></p>
  
  <p>I need a result like the following:</p>
  
  <pre><code>AnswerId         QuestionId       ...        ...        ...
  </code></pre>
  
  <p>With a maximum of 10 random QuestionId and the number of AnswerId will vary depending of how many answer there is for the 10 random questions.</p>
  
  <p>Thank you for any help.</p>