SQL Inner Join使用选择而不是表名称
我有两个表在表Tab1和tab2上执行内部连接的表格有不同的长度,但在TAB1_COL2和TAB2_COL2(alias_2/alias_4)中具有常见数据,
select
tab1_col1 as alias_1,
tab1_col2 as alias_2,
from db.schema.tab1
inner join (
select
tab2_col1 as alias_3,
tab2_col2 as alias_4,
tab2_colx as alias_x
from db.schema.tab2
) on db.schema.tab1.alias_2 = db.schema.tab2.alias_4
我一直在遇到错误,但有“ TAB2”的条目,但是在查询的这一部分中无法引用它。
I have two tables that I'm trying to perform an Inner join on tables tab1 and tab2 have different lengths but have common data in tab1_col2 and tab2_col2 (alias_2/alias_4)
select
tab1_col1 as alias_1,
tab1_col2 as alias_2,
from db.schema.tab1
inner join (
select
tab2_col1 as alias_3,
tab2_col2 as alias_4,
tab2_colx as alias_x
from db.schema.tab2
) on db.schema.tab1.alias_2 = db.schema.tab2.alias_4
I keep on getting the error there is an entry for "tab2" but it can't be referenced in this part of the query.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
订单中除外),因此您无法在联接条件下访问
alias_2
。您必须使用实际的列名。order by
clause) so you can't accessalias_2
in your join condition. You have to use the actual column name.