Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » ElevateDB Technical Support » Support Forums » ElevateDB SQL » View Thread |
Messages 1 to 3 of 3 total |
select question |
Tue, Jul 24 2007 8:56 AM | Permanent Link |
"Harry de Boer" | LS
Tables: Customers, Orders, Order_Detail How do I create a select statement that shows id_customer, id_order but only when there is more then 1 orderdetail record? Regards, Harry |
Tue, Jul 24 2007 10:26 AM | Permanent Link |
"Ole Willy Tuv" | Harry,
<< Tables: Customers, Orders, Order_Detail How do I create a select statement that shows id_customer, id_order but only when there is more then 1 orderdetail record? >> A couple of alternatives: 1) select c.CustomerID, o.OrderID from Customers c join Orders o on o.CustomerID = c.CustomerID join Order_Detail od on od.OrderID = o.OrderID group by c.CustomerID, o.OrderID having count(od.OrderID) > 1 2) select c.CustomerID, o.OrderID from Customers c join Orders o on o.CustomerID = c.CustomerID where o.OrderID in ( select OrderID from Order_Detail group by OrderID having count(OrderID) > 1 ) Ole Willy Tuv |
Tue, Jul 24 2007 11:31 AM | Permanent Link |
"Harry de Boer" | Ole,
Thanks. I'll go for alternative 1 (seems to be a bit faster). Regards, Harry "Ole Willy Tuv" <owtuv@online.no> schreef in bericht news:81B529EC-4ED4-44FB-81EC-E2F7A07AC69F@news.elevatesoft.com... > Harry, > > << Tables: Customers, Orders, Order_Detail > > How do I create a select statement that shows id_customer, id_order but only > when there is more then 1 orderdetail record? >> > > A couple of alternatives: > > 1) > > select > c.CustomerID, > o.OrderID > from > Customers c > join Orders o on o.CustomerID = c.CustomerID > join Order_Detail od on od.OrderID = o.OrderID > group by c.CustomerID, o.OrderID > having count(od.OrderID) > 1 > > 2) > > select > c.CustomerID, > o.OrderID > from > Customers c > join Orders o on o.CustomerID = c.CustomerID > where o.OrderID in > ( > select OrderID > from Order_Detail > group by OrderID > having count(OrderID) > 1 > ) > > Ole Willy Tuv > > |
This web page was last updated on Tuesday, April 30, 2024 at 03:55 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |