This is fantastic and exactly what I needed. Thanks!
I see now that instance can refer to many different things (resource, url, etc.) and you need to see the moduleid to see the type of resource so you know which table to match with.
You've opened my eyes.
By the way, is there any documentation on the database design to help those of us who are still pretty new at it?