ok, let's sart simple...your first query. why not just...select e.productnum, SUM(e.quantity) as quantityfrom orderlineitem e where e.parentOrderlineitemid is null group by e.productnumorder by sum(e.Quantity) desc
so your second would be like...select p.somecol,e.productnum, SUM(e.quantity) as quantityfrom orderlineitem e join product p on p.productnum = e.productnumwhere e.parentOrderlineitemid is null group by e.productnum, p.SomeColorder by sum(e.Quantity) desc
Em