Adding complex query