Joining without using a key

C

CAM

Hello,

I need an expert on this one who has encounter a similar situtation. I have
two tables that I am trying to join, the problem is that none of the tables
have a unique key making it hard to join properly. The first tables contain
the following fields:

Audit Table
PolicyNumber - (Text field)
Received Date - (Date field)

The other table is called - Invoice
Policy_Number - (Text field)
Invoice Date - (Date field)


Here is an example of what I am trying to match.

In the Audit Table I trying to match PolicyNumber with the Policy_Number in
the Invoice table. In this case I am using the same policy number, but they
have different Received Date in the Audit Table:

PolicyNumber Received Date
XX12 4/5/2006
XX12 4/18/2006
XX12 4/26/2006

In the Invoice table I have the following:

Policy_Number Invoice Date
XX12 4/8/2006
XX12 4/21/2006
XX12 4/30/2006



I not getting the correct result. The policies are matching correctly.:
Below is what it should look like

PolicyNumber Received Date Invoice Date
XX12 4/5/2006 4/8/2006
XX12 4/18/2006 4/21/2006
XX12 4/26/2006 4/30/2006


The key here is that the Invoice Date will be before the next same policy
Received Date on the Audit table: For example PolicyNumber XX12 Received
4/5/2006 must match with the Invoice table dated 4/8/2006. Likewise the
Received Date on the same policy number at 4/18/2006 should match with
4/21/2006 Invoice table and Received date 4/26/2006 must match with invoice
date 4/30/2006. It is difficult to match, especially when there is no
primary key. The policy numbers are not unique at all the only thing that
is unique is the received date and the invoice date. If anyone has an idea
I would really appreciate the help. This is a major problem for the
database I am creating. Anybody with has any tips or suggest to visit a
website I will appreciate the help. Thank you in advance
 
S

strive4peace

Link on PolicyNumber
Use a Group/totals query

then, also on the grid:

field --> [Received Date]
Totals --> Max
criteria --> <= [Invoice Date]


Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
J

John Spencer

I believe to get the results you want, you will need a coordinated subquery in
the where clause. I would try the following.

SELECT Audit.PolicyNumber
, Audit.ReceivedDate
, Policy.InvoiceDate
FROM Audit INNER JOIN Invoice
ON Audit.PolicyNumber = Invoice.PolicyNumber
WHERE InvoiceDate =
(SELECT Min(InvoiceDate)
FROM Invoice As I
WHERE I.InvoiceDate >= Audit.ReceivedDate
AND I.PolicyNumber = Audit.PolicyNumber)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top