Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / March 2008

Tip: Looking for answers? Try searching our database.

SQL join question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jmoseby_@_elasticfabrics.com - 27 Mar 2008 14:51 GMT
The following SQL results in some (not all) records being doubled in
the SUM()'d column.  This occurs when I add in the LEFT OUTER JOIN'd
table.  I can't for the life of me figure out why.  Am I missing
something obvious?

SELECT  
      max(OB003.LTCUSTSN),
      max(OB002.FGSTYLE),
      max(OB002.FGLINWID),
      max(OB002.FGCOLOR),
      max(OB1002.CRDESC),
      max(OB002.FGSHASPC),
      sum(OB002.FGYARDS),
      OB002.FGLOT#,
      max(OB003.LTCOMMTS),
      max(OB002.FGORDER#),
      max(OB003.LTDUEDAT),
      OB002.FGROLSTS,
      max((days(CURRENT_DATE)-days(OB002.FGPRDDT)))    
FROM      
   S10726EA.OBPRDDTA.OB002 OB002      
INNER JOIN      
   S10726EA.OBPRDDTA.OB003 OB003  
ON
      OB002.FGLOT# = OB003.LTLOT#    
LEFT OUTER JOIN
      S10726EA.OBPRDDTA.OB1002 OB1002  
ON
      OB002.FGCOLOR = OB1002.CRCOLOR  
WHERE
      OB002.FGROLSTS in (8,10)    
AND
      OB002.FGQUALTY in ('FS', 'RW')    
AND
      ((OB003.LTLOTSTS between 55 and 61) OR (OB003.LTLOTSTS = 35 AND
OB003.LTCOMPLT = 'Y'))    
AND
      OB002.FGPRDDT <= (DATE('03/26/2008') - 90 DAYS)    
GROUP BY
      OB002.FGLOT#,     OB002.FGROLSTS
jmoseby_@_elasticfabrics.com - 27 Mar 2008 15:15 GMT
>The following SQL results in some (not all) records being doubled in
>the SUM()'d column.  This occurs when I add in the LEFT OUTER JOIN'd
>table.  I can't for the life of me figure out why.  Am I missing
>something obvious?
<snip>

Nevermind,

The answer is "YES" I missed something obvious.  Duplicate records in
the LEFT OUTER JOIN'd table.  Duh.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.