|
On 03 Apr 2013 09:52, Stone, Joel wrote:
I have an order header and detail file with one to many.I'd use the following query:
<<SNIP>>
Should I be grouping the detail PRIOR to the join, so there is only
ONE header value?
But it seems like the SQL stmt is SO much simpler if I do the join
first.
With
TotDet as
(Select OrderNo, Sum(DetQty) DetQTY
From OrderDet
Group By OrderNo
)
Select Coalesce(H.OrderNo, D.OrderNo)
, HdrQty, DetQty
From OrderHdr h
full outer join TotDet d
on h.OrderNo = d.OrderNo
Where HdrQty <> DetQty
or HdrQty is NULL
or DetQty is NULL
;
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.