Handling Complex Database Queries