To be honest, I dislike remembering the SQL statements. I never believe the SQL is a programming language in general. Apart from the simple case of use, there are many dialects used to manipulate complexities a bit, and there is many a pitfall, more's the pity. Those beat me up, and push me over the edge again and again.
This module would be useful to you like pitiful me. Of course, there are several modules of this sort out there, but for the moment I'd like to recommend the module.