I don't know you table names, or column names, but this is the structure of the query given a customer and customer order table, linked by customerid.
Main Topics
Browse All TopicsHow can I query my SQL database and find all the duplicate orders where a customer ordered something more than once?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Depends on what kind of table structure you have really, but let's say you have 3 tables (Customers, Products, Orders).
SELECT c.CustomerID, p.ProductID, COUNT(*)
FROM Customers c
INNER JOIN Orders o ON c.CustomerID = o.CustomerID.
INNER JOIN Products p ON o.OrderID = p.OrderID
GROUP BY c.CustomerID, p.ProductID
HAVING COUNT(*) > 1
Is this what you mean?
SELECT c.CustomerID, p.ProductID, COUNT(*), GETDATE() AS CompleteDate
FROM Customers c
INNER JOIN Orders o ON c.CustomerID = o.CustomerID.
INNER JOIN Products p ON o.OrderID = p.OrderID
GROUP BY c.CustomerID, p.ProductID
HAVING COUNT(*) > 1
or is this what you mean?
SELECT c.CustomerID, p.ProductID, COUNT(*), MAX(o.CompleteDate) AS CompleteDate
FROM Customers c
INNER JOIN Orders o ON c.CustomerID = o.CustomerID.
INNER JOIN Products p ON o.OrderID = p.OrderID
GROUP BY c.CustomerID, p.ProductID
HAVING COUNT(*) > 1
Close.
But sometimes I am getting records that have "orders" (ProcedureID) that have only been ordered once, which is incorrect. Then I want to update RCCompleteDate to Today's date when ProcedureDate is the oldest date. This is what I have so far.
SELECT PatientHistory.PatientID, PatientHistory.ProcedureID
FROM (PatientHistory LEFT JOIN Procedures ON PatientHistory.ProcedureID
WHERE (((PatientHistory.PatientI
ORDER BY PatientHistory.PatientID;
Yes.
PatientID ProcedureID ProcedureDate RCCompleteDate
11 40 3-14-2005
11 40 10-3-2008
The update query should change RCCompleteDate for the oldest ProcedureDate, so it should look like
PatientID ProcedureID ProcedureDate RCCompleteDate
11 40 3-14-2005 10-3-2008
11 40 10-3-2008
The most recent ProcedureDate will be the only one with a blank RCCompleteDate.
Thanks for your help.
Business Accounts
Answer for Membership
by: chapmandewPosted on 2009-02-27 at 07:53:27ID: 23756685
example
select customerid, productid, count(*)
from orders
group by customerid, productid
having count(*) > 1