How do I count referenced records? (Mysql)

Goal: I want a amount_of_lectures column in my courses table, which counts all lectures that reference this course.

This is what I want and how the db model looks like:

I was thinking of doing the count in the query - but then I add a bunch of unnecessary load I think. This query is executed often, and the amount_of_lectures will change perhaps once a year or so.

My best idea is to make a MySQL expression that counts, but I have no idea where to start and if that is the best approach.

Any suggestions on how to approach this?

Community Page
Last updated: