我有两个查询,其中一个依赖于另一个的输入:
查询#1:
SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER='12345'
这将返回与持有人ACCOUNT_ID
12345
列表
然后,我需要将这些account IDs
传递给以下查询,以显示与所有已获取的帐户ID相关联的交易列表
SELECT TRANS_ID, ACCOUNT_ID, "REF"
FROM ISET.ENTRY
WHERE ACCOUNT_ID='LIST OF ACCOUNT IDS';
我如何才能找到最有效的方法呢?
感谢您的光临。
答案 0 :(得分:3)
只需使用与IN
语句相结合的子选择。
SELECT TRANS_ID, ACCOUNT_ID, "REF"
FROM ISET.ENTRY
WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER='12345');
答案 1 :(得分:2)
SELECT TRANS_ID, ACCOUNT_ID, 'REF'
FROM ISET.ENTRY
WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER='12345');
答案 2 :(得分:2)
使用IN
:
SELECT TRANS_ID, ACCOUNT_ID, "REF"
FROM ISET.ENTRY
WHERE ACCOUNT_ID IN (SELECT ACCOUNT_ID
FROM ISET.ACCOUNT
WHERE HOLDER = '12345'
);