by Corey Wallis.
Hi,
This page in the Moodle Developer Documentation website covers all of the ways to query the database.
http://docs.moodle.org/dev/Data_manipulation_API
Hope this helps.
-Corey