**Bug description**

Select from table with Engine=Set does not work with 2 joins.

**Affected version**

Reproduces on 21.3.15.4

**How to reproduce**

Creating base table and set table:

```sql
CREATE TABLE users (
  userid UInt64
)
ENGINE = MergeTree() ORDER BY (userid);
INSERT INTO users VALUES (1),(2),(3);

CREATE TABLE users_set (
  userid UInt64
)
ENGINE = Set;
INSERT INTO users_set VALUES (1),(2);

-- works
select * from users where userid in users_set;
```

Adding one more table and one more join:

```sql
CREATE TABLE user_names(
    userid UInt64,
    name String
) ENGINE = MergeTree() ORDER BY (userid);

INSERT INTO user_names VALUES (1, 'Batman'), (2, 'Joker'), (3, 'Superman');

-- still works
select userid, name 
from users any left join user_names on (users.userid = user_names.userid) 
where userid in users_set;
```

And one more table plus 2nd join breaks it:

```sql
CREATE TABLE user_real_names(
    uid UInt64,
    real_name String
) ENGINE = MergeTree() ORDER BY (uid);

INSERT INTO user_real_names VALUES (1, 'Bruce Wayne'), (2, 'Unknown'), (3, 'Clark Kent');

--DOES NOT WORK
select 
    users.userid,
    name,
    real_name
from users 
    any left join user_names on (users.userid = user_names.userid) 
    any left join user_real_names on (users.userid = user_real_names.uid)
where users.userid in users_set;
```

**Expected behavior**

Working query, just like with one or no joins. Expected output: 

```
1	Batman	Bruce Wayne
2	Joker	Unknown
```

**Error message and/or stacktrace**

```Unknown column name 'users_set': While processing SELECT```

ASTPtr left_table = src_tables[0];
    static ASTPtr subquery_template = makeSubqueryTemplate();
    for (size_t i = 1; i < src_tables.size() - 1; ++i)
    {
        auto expression_list = subqueryExpressionList(i, needed_columns, alias_pushdown);
        ASTPtr subquery = subquery_template->clone();
        SubqueryExpressionsRewriteVisitor::Data expr_rewrite_data{std::move(expression_list)};
        SubqueryExpressionsRewriteVisitor(expr_rewrite_data).visit(subquery);
        left_table = replaceJoin(left_table, src_tables[i], subquery);
    }
    RewriteVisitor::Data visitor_data{left_table, src_tables.back()};
    RewriteVisitor(visitor_data).visit(select.refTables());
    data.done = true;
}
ASTPtr JoinToSubqueryTransformMatcher::replaceJoin(ASTPtr ast_left, ASTPtr ast_right, ASTPtr subquery_template)
{
    const auto * left = ast_left->as<ASTTablesInSelectQueryElement>();
    const auto * right = ast_right->as<ASTTablesInSelectQueryElement>();
    if (!left || !right)
        throw Exception("Two TablesInSelectQueryElements expected", ErrorCodes::LOGICAL_ERROR);
    if (!right->table_join)
        throw Exception("Table join expected", ErrorCodes::LOGICAL_ERROR);
    
    RewriteVisitor::Data visitor_data{ast_left, ast_right};
    RewriteVisitor(visitor_data).visit(subquery_template);
    return subquery_template;
}
}