complex query setup