Link to home
Start Free TrialLog in
Avatar of Star Gazr1
Star Gazr1Flag for United States of America

asked on

SQL Query

I am working with a Select Query (SQL Server 2000) where I want to filter for the number of orders being placed for a specific item. For the Query below
I want to bring back only customers who placed an order for ItemCode='100' more than two times. Any ideas on how I can do this?  Thanks.


Select Customer.CustomerID
from Customer
JOIN Orders on Customer.CustomerID = Orders.CustomerID
WHERE
Orders.ItemCode ='100'
SOLUTION
Avatar of mimran18
mimran18
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Select Customer.CustomerID
from Customer
JOIN Orders on Customer.CustomerID = Orders.CustomerID
WHERE
Orders.ItemCode ='100'
and Customer.customerID HAVING COUNT(*) > 2
Avatar of Star Gazr1

ASKER

thanks for both replies.  Both queries look similar.  Which one is correct or does it matter?
ASKER CERTIFIED SOLUTION
Avatar of Anthony Perkins
Anthony Perkins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help