I am creating a quiz web app. I have two tables: one table with questions, the other with answers. There is one question to many answers, and there are many answers to one question. The length of the answers may vary. For example, one question may have 2 answers, while another may have 5 possible answers.
Here is a silly example:
Questions table:
+-------------+-----------------------------+------------------+
| id | question | correct_answer |
+-------------+-----------------------------+------------------+
| 1 | What is my name? | 2 |
+-------------+-----------------------------+------------------+
| 2 | 'Green' is a color. | 1 |
+-------------+-----------------------------+------------------+
Answers table:
+-------------+---------------+-----------------+---------------+
| id | question_id | answer | answer_num |
+-------------+---------------+-----------------+---------------+
| 1 | 1 | Tom | 1 |
+-------------+---------------+-----------------+---------------+
| 2 | 1 | Hayden | 2 |
+-------------+---------------+-----------------+---------------+
| 3 | 1 | Chris | 3 |
+-------------+---------------+-----------------+---------------+
| 4 | 1 | Gale | 4 |
+-------------+---------------+-----------------+---------------+
| 5 | 2 | true | 1 |
+-------------+---------------+-----------------+---------------+
| 6 | 2 | false | 2 |
+-------------+---------------+-----------------+---------------+
I am wanting to select the questions and possible answers to that question in one query, versus making multiple queries, especially nested ones in a loop, which is bad.