|
Eric, Thanks for the info, I personally prefer using the ON join for filtering also. I like the syntax better in that it keeps the join/filter fields with the related file, but had never thought that it might be a better performer. Duane Christen -----Original Message----- From: DeLong, Eric [mailto:EDeLong@xxxxxxxxxxxxxxx] Sent: Friday, November 11, 2005 9:17 AM To: 'RPG programming on the AS400 / iSeries' Subject: RE: Returning Values from two different Tables Duane, I've noticed similar performance improvements when using CTE constructs. I suppose I always assumed that the CTE expressions were faster because it potentially reduces the number of rows to process, which allows the joins to process faster. I generally use CTE to pre-summarize sales data before producing report data... with SlsCy (Cust, Sales, Cost, TrnCnt) as ( Select Cst#, sum(Extd-Disc), sum(Cost), count(distinct order#) from saleshist where tdate >= '2005-10-01' and tdate <= '2005-10-31' ), SlsLy (Cust, Sales, Cost, TrnCnt) as ( Select Cst#, sum(Extd-Disc), sum(Cost), count(distinct order#) from saleshist where tdate >= '2004-10-01' and tdate <= '2004-10-31' ) /* Show all current-year customers, with their sales from last year.... */ Select SlsCy.Cust, SlsCy.Sales, SlsLy.Sales .... >From SlsCy left outer join SlsLy on (SlsCy.Cust=SlsLy.Cust) Union All /* Now, add in the customers with sales last year, but not this year....... */ Select SlsCy.Cust, SlsCy.Sales, SlsLy.Sales .... >From SlsLy exception join SlsCy on (SlsCy.Cust=SlsLy.Cust) (I wish DB2/400 supported full join......) A similar benefit seems to occur when you move filtering in a join statement from the Where clause into the ON join criteria. It's particularly noticable when joining very large files into a summary result set, such as for a dashboard sales report. Eric DeLong Sally Beauty Company MIS-Project Manager (BSG) 940-297-2863 or ext. 1863 NOTICE: This electronic mail transmission may contain confidential information and is intended only for the person(s) named. Any use, copying or disclosure by any other person is strictly prohibited. If you have received this transmission in error, please notify the sender via e-mail.
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 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.