That is a long and complex query that even has a 5 second sleep built into it. I'm not sure who wrote that query or what it is for, but I can probably help you re-write it and make it more efficient in our support session.
Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.
These out-of-the-box solutions provide you proven, tested applications that can be up and running now. Build a store, a gallery, or a web-based email solution.