Here's my current query:
SELECT questions.question, questions_headings.title FROM questions JOIN questions_headings ON questions.heading=questions_headings.id WHERE questions.heading IN (1,2,3) ORDER BY RANDOM() LIMIT 10
Basically, the database contains Questions for various Headings. For example:
questions_headings:
+----+-------+
| id | title |
+----+-------+
| 0 | blah1 |
+----+-------+
| 1 | lol1 |
+----+-------+
| 2 | etc1 |
+----+-------+
questions:
+----+---------+----------+
| id | heading | question |
+----+---------+----------+
| 0 | 1 | howdoi |
+----+---------+----------+
| 1 | 0 | blahques |
+----+---------+----------+
| 2 | 1 | herro |
+----+---------+----------+
What my query does is randomly selects X amount of questions from the given headings and shows them to the user.
Currently, if you want 10 random questions (LIMIT 10), it gives you 10 random questions across all IDs. Normal, right? But I don't want this.
What I need the query to do is, pull out 10 random questions distributed across the given IDs. That way, I won't end up with 9 questions from one heading and 1 question from the other.
Hope that made sense...
Is it possible to do this with just SQL?