防止 DB2 'USING' 子句隐藏 SELECT [星号]..返回的字段?

Prevent the DB2 'USING' clause from hiding fields returned by SELECT [asterisk]..?

我正在使用 DB2/400 v7r3。我最近发现 INNER JOIN 的一个问题,如果 SELECT 语句使用 *(星号)到 return 中的所有字段,则 USING 子句会隐藏字段连接的表。

如何防止 USING 子句执行此操作..?

我确实发现如果使用 ON FIELDA=FIELDB 样式,所有字段都会正确显示。但这违背了使用 USING 子句的目的,以及使复杂连接更紧凑的优势。

我在文档中找不到关于此行为的任何内容:

这是一个例子。两个表都有 X、Y 和 Z 三列:

-- THIS ONLY RETURNS COLUMN Z
SELECT     B.*
FROM       TABLE1 AS A
INNER JOIN TABLE2 AS B 
           USING(X, Y)

-- THIS RETURNS ALL COLUMNS, X, Y, AND Z.
SELECT     B.*
FROM       TABLE1 AS A
INNER JOIN TABLE2 AS B
           ON A.X=B.X
           ON A.Y=B.Y

按设计工作...

The result table of the join contains the columns from the USING clause first, then the columns from the first table of the join that were not in the USING clause, followed by the remaining columns from the second table of the join that were not in the USING clause. Any column specified in the USING clause cannot be qualified in the query.

https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/db2/rbafzjoinedt.htm

当您使用 USING 时,结果集中仅包含 named-columns 的一个副本。

这就是你想要做的...

SELECT     X, Y, B.*
FROM       TABLE1 AS A
INNER JOIN TABLE2 AS B 
           USING(X, Y)