Background: Two different document types in a document management system. Both Doc Type A and Doc Type B have a Ticket #, and a Ticket Date. What we're looking for: Doc Type A docs that don't have a matching Doc Type B doc (NOT EXISTS) with the same Ticket # and Ticket Date. There like are Doc Type B docs that have the same Ticket # but NOT the same Ticket Date. We want to ignore those. Seems simple.... but I am stuck. So far what I have is something like this:
SELECT
DISTINCT ki110.keyvaluechar AS "Ticket #",
ki101.keyvaluedate AS "Ticket Date"
FROM
itemdata
LEFT OUTER JOIN
hsi.keyitem110 ki110 on ( itemdata.itemnum = ki110.itemnum )
LEFT OUTER JOIN
hsi.keyitem101 ki101 on ( itemdata.itemnum = ki101.itemnum )
WHERE
ki101.keyvaluedate BETWEEN '01-01-2021' AND '01-31-2021'
AND
(
itemdata.itemtypenum = 178
) -- this is Doc Type A
AND NOT EXISTS
(
SELECT
ki110.keyvaluechar,
ki101.keyvaluedate
FROM
itemdata,
keyitem110 ki110 ,
keyitem101 ki101
WHERE --(itemdata.itemnum = ki110.itemnum) --Ticket #
-- ** the problem is here for Date: I need to say Date in Doc Type B doc is not the same as Date in Doc Type A doc using ki101.keyvaluedate)
AND itemdata.itemtypenum = 183) -- this is DOC Type B