Hi,
Does it really have to be so complex?
You need to simplify things. Think about what could be unnecessary and get rid of that. I don't know the business requirements, but maybe you could split this into parts?
You should read and learn about query optimization. I would recommend to read this (if you're using
SQL Server):
SQL SERVER – Tips for SQL Query Optimization by Analyzing Query Plan[
^]
BTW, are you not missing a
WHERE statement at the end of this select?