need help fast!

S

sn0w0wl

I've been pulling my hair out trying to figure out how to make this query...

I need to make a list of repeat customers...there's 10 customers total and
only 2 are repeat...

how do I get the query to show only the repeat customers?
 
D

Douglas J. Steele

You mean you want to know which customers show up in the list more than
once?

You can use a query like:

SELECT CustomerID
FROM MyTable
GROUP BY CustomerID
HAVING Count(*) > 1

To get the details for those customers, you can use that as a subquery
against your Customer table:

SELECT CustomerID, CustomerName, CustomerAddress, ...
FROM Customer
WHERE CustomerID IN (SELECT CustomerID
FROM MyTable
GROUP BY CustomerID
HAVING Count(*) > 1)
 
S

sn0w0wl

OMG thank you soooo much....you're a life saver!

Douglas J. Steele said:
You mean you want to know which customers show up in the list more than
once?

You can use a query like:

SELECT CustomerID
FROM MyTable
GROUP BY CustomerID
HAVING Count(*) > 1

To get the details for those customers, you can use that as a subquery
against your Customer table:

SELECT CustomerID, CustomerName, CustomerAddress, ...
FROM Customer
WHERE CustomerID IN (SELECT CustomerID
FROM MyTable
GROUP BY CustomerID
HAVING Count(*) > 1)
 
Top