I have the following database schema:
table courses:
id
tutor_id
title
table course_categories:
id
category_id
course_id
table categories:
id
name
table tutors:
id
name
table subscribers:
id
course_id
user_id
I need to make 1 sql to get a course with all it’s categories, and the tutor for that course and the number of subscribers for that course. Can this be done in 1 query? Should this be done using stored procedures?
With this query you get what you want:
I used
left joinonsubscribersbecause there might be no one for a givencourse. I’m assuming that all the other tables have data on it for everycourse,categorieandtutor. If not, you can userleft joinas well but then you’ll have data with null.