Oracle 10g, SQL Query to count missing rows

I need a query to count the number of rows missing between two tables. Pretty simple, this works fine;
from E_ORD_D5 
where comp_code = 'A1' 
and ord_num = 916393
and ORD_LINE_NUM not in (
select ord_line_num from E_ord_d5d2
where comp_code = 'A1'
and ord_num = 916393)

Open in new window

Heres where I am stuck..  the query has 2 parameter fields COMP_CODE and ORD_NUM. Each is currently used twice. My application will only pass the two values one time.  How can I add joins to this query so that the parameters are only set once?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

johnsoneSenior Oracle DBACommented:
Correlated subquery.
SELECT Count(ord_line_num) 
FROM   e_ord_d5 
WHERE  comp_code = 'A1' 
       AND ord_num = 916393 
       AND ord_line_num NOT IN (SELECT ord_line_num 
                                FROM   e_ord_d5d2 
                                WHERE  comp_code = e_ord_d5.comp_code 
                                       AND ord_num = e_ord_d5.ord_num) 

Open in new window

Reference the table in the outer query from the inner query.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JDCamAuthor Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.