Database query fix