Fixed silly sql inefficiency