SQL in Moodle

Does anyone have any experience of using custom reports in Moodle to build reports based on their SQL databases. (It seems like the syntax is not the same as I learned eg using LIMIT does not seem to work.
Once I have anyone who responds, I can start asking some specific questions. Thanks