Re: Find records without any corresponding record in another table
From: Gerald Stanley (gcstanley_at_dsl.pipex.com)
Date: 03/31/04
- Next message: AHopper: "Re: Missing Numbers"
- Previous message: Duane Hookom: "Re: Query Syntax error for Concatenate"
- In reply to: Brad: "Find records without any corresponding record in another table"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 31 Mar 2004 10:43:07 -0800
Try
SELECT tblLoanData.LoanID, Max(tblPayments.Date) AS LastPayment
FROM tblLoanData LEFT JOIN tblPayments ON
tblLoanData.LoanID = tblPayments.LoanID
GROUP BY tblLoanData.LoanID, tblLoanData.Deleted,
tblPayments.Deleted, tblPayments.Type
HAVING (((tblLoanData.Deleted)=False) AND
((tblPayments.Deleted)=False) AND
((tblPayments.Type)='Full/Partial Payment'))
UNION
SELECT tblLoanData.LoanID , Null
FROM tblLoanData
WHERE tblLoanData.LoanID NOT IN (SELECT DISTINCT
tblPayments.LoanID FROM tblPayments)
Hope This Helps
Gerald Stanley MCSD
>-----Original Message-----
>I have the following query:
>
>SELECT tblLoanData.LoanID, Max(tblPayments.Date) AS
LastPayment
>FROM tblLoanData LEFT JOIN tblPayments ON
tblLoanData.LoanID = tblPayments.LoanID
>GROUP BY tblLoanData.LoanID, tblLoanData.Deleted,
tblPayments.Deleted, tblPayments.Type
>HAVING (((tblLoanData.Deleted)=False) AND
((tblPayments.Deleted)=False) AND
((tblPayments.Type)='Full/Partial Payment'))
>
>So I want the LoanID and last payment date (loan is not
deleted, payment is not deleted)
>This works fine unless there is no payment for a
particular loan. How do I rework the query to give me a
null value for last payment if there is no payment record?
>
>Thanks in advance!
>.
>
- Next message: AHopper: "Re: Missing Numbers"
- Previous message: Duane Hookom: "Re: Query Syntax error for Concatenate"
- In reply to: Brad: "Find records without any corresponding record in another table"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|