Problem
How to select rows from table shippolicyh that have related one row only on table trxfootersafe ?
meaning to modify query that get all policycode on shippolicyh that have one row only related on
table trxfootersafe .
the following query not give me result
so that what I change .
Sample to result
policycode 1211 must not show because it have two lines on trxfootersafe table .
<pre lang="SQL">Shippolicyh
BranchCode, PolicyCode EgyPolicyNum Sender
1 1211 3494939 12
trxfootersafe
serial year subldgcode1 subldgcode2 debit credit typetrxsafe
50 2019 12 1211 0 90 -1
55 2019 12 1211 90 0 1
policycode 5555 must show because it have one lines only on trxfootersafe table .
Shippolicyh
BranchCode, PolicyCode EgyPolicyNum Sender
1 5555 3494939 12
trxfootersafe
serial year subldgcode1 subldgcode2 debit credit typetrxsafe
70 2019 12 5555 90 0 -1
but problem that query above show all policy code on shippolicyh table that have one line or two lines
so that how to make it show one line related only
meaning show policy code number 5555 because it have one line
and not show policy code 1211 because it have two lines
What I have tried:
SELECT
BranchCode,PolicyCode,PolicyDate,EgyPolicyNum
FROM
SHIPPolicyH H
WHERE
EXISTS (
SELECT
COUNT (*)
FROM
TrxFooterSafe F
WHERE
SubLdgCode2 = H.PolicyCode AND BranchCode = H.BranchCode AND SubLdgCode1=H.Sender and BranchCode=1 and Debit > 0 and Credit=0 and TypeTrxSafeCode=-1
GROUP BY
SubLdgCode2,SubLdgCode1
HAVING
COUNT (*) =1
)
ORDER BY
PolicyCode,
BranchCode;