admin管理员组文章数量:1278983
I want to combine two result sets
ResultSetA
ID | ID_EXT | List_A |
---|---|---|
1 | 1_ | 1,2,3,4,5 |
2 | 1_ | 20,30,50 |
I want to combine two result sets
ResultSetA
ID | ID_EXT | List_A |
---|---|---|
1 | 1_ | 1,2,3,4,5 |
2 | 1_ | 20,30,50 |
ResultSetB
ID | ID_EXT | List_B |
---|---|---|
1 | 1_ | B01,B0 |
2 | 1_ | B20,B30,B50 |
ResultSet should be
ID | ID_EXT | List_A | List_B |
---|---|---|---|
1 | 1_ | 1,2,3,4,5 | B01,B0 |
2 | 1_ | 20,30,50 | B20,B30,B50 |
- We need to also see the queries that generated the two original result sets. – Tim Biegeleisen Commented Feb 24 at 14:21
- It's a quite bit complex to insert the queries here, but it is a with clause. – sensen ol Commented Feb 24 at 14:35
1 Answer
Reset to default 2Assuming each result set can be obtained by querying some CTE, then you only need a join here:
SELECT
a.ID,
a.ID_EXT,
a.List_A,
b.List_B
FROM cteA a
INNER JOIN cteB b
ON b.ID = a.ID AND
b.ID_EXT = a.ID_EXT
ORDER BY
a.ID,
a.ID_EXT;
The above logic might have to change, depending on whether or not a record in either CTE result set might not match to the other one. In that case, a left join or perhaps a full outer join might be more appropriate.
本文标签: DB2 Combine sql resultsStack Overflow
版权声明:本文标题:DB2 Combine sql results - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741265219a2368333.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论