I have exhausted all examples I can find and I am still not getting the results I need.
I have an invoice table where I need to find any instance where the same invoice number is used on more than one customer. An invoice number can occur multiple times in the table and each record is distinguished by invoice and invoice seq no, but there should only be one customer per invoice, but some errors have crept in.
What I need is a report of only those invoice that have two or more customers. In the data below Cust 45001301 should not be the customer number for Invoice 708, seq 3.
Cust No Invoice No Seq No Input Date
700180 708 1 9/30/2007
700180 708 2 9/30/2007
45001301 708 3 9/30/2007
700180 708 4 9/30/2007
700190 709 1 9/30/2007
700190 709 2 9/30/2007
What I have tried to do is just get a simple group by query to show me only those invoices with more than one customer much like this-
[Invoice No] [Cust no]
708 700180
708 45001301
But I ONLY want to see those with two or more customers, so in the above example I would not see the entry for invoice 709 because it only has the one customer.
[Invoice No] [Cust no]
708 700180
708 45001301
709 700190
First create a query which returns all distinct combinations of
[Invoice No]and[Cust no]. Then use that as a subquery where you count the number of customers per[Invoice No]and add aHAVINGclause to limit the output to only those where the count is greater than one.If you then need to see which customers where duplicated for those invoices,
INNER JOINthat query back to theInvoicestable.With Access 2007 and your sample data in a table named
Invoices, that query gives me this result set:If you actually wanted to see all the data for those duplicate invoice numbers, change the first line of the second query to this: