select from orders where product purchased by same customer
Posted: Tue Mar 03, 2009 3:30 pm
I need to do a query on my orders table for anybody who bought a specific product more than once. I understand how to do the joins on the cart items and order tables, but I am not so sure how I would only select those who have bought a product more than once.
For instance, let's assume my table looks like this, and the specific product is "book".
With the given data, I'd want my query to return rows 3,4,7 & 8. I'd want these because the same person bought "book" multiple times. How would I go about this?
For instance, let's assume my table looks like this, and the specific product is "book".
Code: Select all
orderid buyerID orderdate item
1 1 2/15/2008 rock
2 2 2/15/2008 cheese
3 3 2/19/2005 book
4 3 3/5/2008 book
5 4 2/15/2008 book
6 5 9/21/2007 milk
7 6 7/14/2007 book
8 6 4/23/2006 book
9 6 6/6/2003 chapstick