Reputation: 42
i have a problem. I have a table on my website with 3 columns like this:
This data is out of 2 database tables, the title and yes/no columns are from the table quizzes and the Number of questions is out of the questions table. I want that users can sort per column, so that you can sort the title asc and desc. I already have this with title and yes/no but not with questions because i dont know how to do that in 1 sql query.
The outcome of that sql query should be the Title, the number of questions that quiz has and if it is yes or no.
If this is to vague please tell me so i will try to write a better explanation. if you need an example of the database please tell me too.
Upvotes: 2
Views: 63
Reputation: 1712
The query could be something like :
SELECT quizes.title, quizes.id, count(q.id) AS aantal
FROM quizes
LEFT JOIN questions AS q ON q.quizid= quizes.id
GROUP BY quizes.title, quizes.id
ORDER BY aantal DESC
edit
changed names of table and columns as comments reveilled them
Upvotes: 1