Q:

One to many select statement

I have quizzes table with columns id, quiz_name, owner_user_id and second table called user_answer with columns id, quiz_id, user_id, answer_id
I want to select quiz name, quiz id, and all users who played particular quiz with the given id. Can I do this with one SQL statement?
Later I need to pass this result in JSON

A:

Yes, you can. You need to join tables on quiz_id and select everything you want.
This is the code if you want quiz name, quiz id and user ids.
SELECT q.quiz_name, q.id, u.user_id 
from quizzes q join user_answer u on (q.id = u.quiz_id) 
where q.id = {yourID}

