I'm glad that helped-- it seems like you're on the right track! You'll need to look at each of the activity types you want to test to find out where (or if) the course ID is stored. In the case of book chapters, you may need to link them through books first. Also, if you need to get links from individual quiz questions, not just from a quiz introduction/description, you'll need to link in the question table.
The "resources" table in Moodle actually refers to uploaded files. There is a separate "page" table that you will need to run the query on. You may want to check the Moodle schemae to see what the different tables are that might be holding the links you're looking for: https://docs.moodle.org/dev/Database_Schema