It’s our pleasure to share your problem which actually turns into a learning process. I would suggest you to first run the mysql query in the SQL console with your table prefix for a particular course and user id and check whether the SQL query is working properly. If the query is working properly, turn on the debugging in your Moodle site from the sitemap given below:
site administration -> development -> debugging
This will describe the error "error reading from database" in more details. Kindly provide us the error screenshot so that we can give you the exact solution.
Till then, keep on Moodling!
Purnendu
DualCube