Fixed sql for empty histories list