I am trying to confirm that a process which sends document_id with a direction flag = 'O' and receives that same document_id back and records it in the same table, but in a new line and different column: src_document_id, with a direction = 'I'.
Need to identify records that were sent, (Direction flag = O) that do not have a matching value for the src_document_id where direction_flag = 'I'. Not sure if I use EXISTS or Not Exists when I check the Outbound value against the Inbound value.
EX in below table: Query should return Document_id 34567 as that does not have a corresponding src_document_id with Direction_flag = I.
select
document_id
from
DOCUMENT_TABLE
where
direction_flag = 'O'
and
client_id = '9999'
and
EXISTS
(
select
document_id
from
DOCUMENT_TABLE
where
document_id != src_document_id and direction_flag = 'I'
)
Hopefully, I am being clear enough. Not well versed in SQL.
DOCUMENT_ TABLE:
Document_id client number Direction flag src_document_id
12345 9999 O
23456 9999 O
34567 9999 O
aaaaa I 12345
aaaab I 23456