Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
-Dman100-
Posting Yak Master
210 Posts |
Posted - 2005-09-21 : 15:32:14
|
Hello,I'm still getting familiar with joins and needed some help.I have the following tables:customers: customerid [pk], name, address, emailproducts: productid [pk], name, priceorders: orderid [pk], customerid [fk], ordertotal, orderdateorderitems: orderitemid [pk], orderid [fk], productid [fk], orderitemqtyHow would I write the sql to return all products that have been bought more than 5 times?Thanks for any help.Regards,-D- |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-09-21 : 15:48:26
|
Try this:SELECT p.name, COUNT(*)FROM products pINNER JOIN orderitems oiON p.productid = oi.orderitemidINNER JOIN orders oON oi.orderid = o.orderidGROUP BY p.nameHAVING COUNT(*) >= 5Tara |
|
|
-Dman100-
Posting Yak Master
210 Posts |
Posted - 2005-09-21 : 16:23:57
|
Thank you Tara...I appreciate your help.Regards,-D- |
|
|
|
|
|
|
|