group by query advice

I need a way to identify records in a table. There are 3 key columns of interest, one is "invoice number", one is "amount", and one is "supplier ID". I need a way of grouping records where invoice number and amount are the same for as many rows as that is the case, and then to filter to identify instances where there are more than one supplier ID against the identical invoice number and amount.
LVL 3
pma111Asked:
Who is Participating?
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.

mbizupCommented:
See if this gives you a count of suppliers for Invoice/Amount combinations:

SELECT  InvoiceNumber, Amount, 
(SELECT COUNT(SupplierID)  FROM YourTable b WHERE b.InvoiceNumber = a.InvoiceNumber AND b.Amount = a.Amount)  As NumberOfSuppliers
FROM YourTable a

Open in new window

0
pma111Author Commented:
that gives a syntax error in access and highlights "(SELECT COUNT(SupplierID)  FROM YourTable b WHERE b.InvoiceNumber = a.InvoiceNumber AND b.Amount = a.Amount)  As NumberOfSuppliers
FROM YourTable a"
0
pma111Author Commented:
and I did replace fieldnames/table names to our ones.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mbizupCommented:
Can you post your SQL?  (what I posted works for me syntactically)...
0
mbizupCommented:
Actually... Try this instead.  My last post wont give you distinct suppliers.  Make sure that any field or table names containing spaces or special characters are enclosed in square brackets: [table Name].[Field Name With Spaces]

SELECT Count(q.SupplierID) AS DistinctSuppliers, q.InvoiceNumber, q.amount
FROM (SELECT DISTINCT a.SupplierID, a.InvoiceNumber, a.Amount
FROM Table1 AS a)  AS q
GROUP BY q.InvoiceNumber, q.amount;

Open in new window

0

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
Ares KurkluSoftware EngineerCommented:
Try this:
SELECT invoiceNo, Count(SupplierId) AS CountOfSupplierId, max(SupplierId) AS SupId, Amount
FROM Table
GROUP BY invoiceNo, Amount, SupplierId;

Open in new window

1
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
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.