Minor sql optimization.