Hi,
One of the most difficult aspects of learning AwareIM for previous developers is to put the old paradigms aside and embrace the AwareIM methodology.
Don't worry about the sql statement, build your query in the tools provided and you will be fine. Once you have built your query, you can look at the sql code developed to answer your own question but I must admit that referencing the actual sql code is not something that I often do as it is not necessary.
When in doubt, read the manual, this really is a lot easier than you are trying to make it.
Cheers,
Pete