I am guessing that you really want:
select d.*
from database1 d
where exists (select 1
from <big query here> q
where q.account_id = d.account_id and
q.transaction_id = d.transaction_id
);
Unlike your query, this guarantees that the two columns are on the same row in your query. That is not what your query does, but I'm guessing it is your intention.
If you really want to check if either occurs anywhere, then you can use a CTE:
with q as (
<your query here>
)
select d.*
from database1 d
where exists (select 1 from q where q.account_id = d.account_id) and
exists (select 1 from q where q.transaction_id = d.transaction_id);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…