fixed issue 1246 with a nested select