Skip to content
Advertisement

Oracle – Data that contains multiple results from IN

I have a dataset of different transaction ids of type 1,2,3,4,5,6,7 as well as many other columns

What I’m trying to do is create different scenarios such as

  • Contains transactions 1 only
  • Contains 1,5 and 7

I’ve started off with a CTE called ALL_CONTRACTS that contains transaction ids of type 1,2,3,4,5,6,7

What’s happening is other contracts that contain a 2,3,4,5,6,7 transaction are showing as they also contain a 1

So how do I pull out only contracts that have a 1 only and not the others?

Advertisement

Answer

Assuming you are trying to find the TRAN_ID for each AGREEMENT_ID/ACCOUNT_NUMBER pair then you can use:

Which, for the sample data:

Outputs:

AGREEMENT_ID ACCOUNT_NUMBER TRAN_ID
1 1 1
5 5 1
5 5 1

db<>fiddle here

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement