Few things that I noticed:
- templateid is a non-persistent field and I couldn't use it in the Where clause;
- to link workorder and commlog tables I used workorder.workorderid = commlog.ownerid;
- I'm not sure how to link directly commtemplate with commlog... in my case I should link workorder <-> commlog <-> escalation <-> commtemplate.
Hope it helps.