Tried to optimize SQL.