title: Joining three DB2 tables
body: <p>I have to join three tables for my report.</p>
  <p>Table1:</p>
  <pre><code>DTL_MTCH_KEY  TRAN_AM   SYS_IND    
    1234567       10        
    1234567       10
    1234567       10
    1234567       10
    2222222       25         Y
    2222222       25         Y
  </code></pre>
  <p>Table2:</p>
  <pre><code>DTL_MTCH_KEY    SUM_TRAN_AM     JR_NAME
     1234567          40          AAAAAAA
     2222222          50          BBBBBBB
  </code></pre>
  <p>Table3:</p>
  <pre><code>DTL_MTCH_KEY   SYS_IND    ERR_MSG 
     2222222        Y       ISSUE WITH PRODUCT 
  </code></pre>
  <p>My output must be like below</p>
  <pre><code>DTL_MTCH_KEY  TRAN_AM   JR_NAME  ERR_MSG 
    1234567       10      AAAAAAA             
    1234567       10      AAAAAAA
    1234567       10      AAAAAAA
    1234567       10      AAAAAAA
    2222222       25      BBBBBBB  ISSUE WITH PRODUCT       
    2222222       25      BBBBBBB  ISSUE WITH PRODUCT 
  </code></pre>
  <p>Requirement.</p>
  <ol>
  <li>I want to join table1, 2 and 3.</li>
  <li>List all the values from Table 1 and get the JR_NAME from table2.</li>
  <li>Whenever Table1 SYS_IND is Y, then get the ERR_MSG from Table3.</li>
  <li>I have to do this in single query.</li>
  </ol>
  <p>I tried below and it bring up duplicate rows. I had 229002 rows in my TABLE1 but my query bring up 385717 rows.</p>
  <pre><code>Select A.DTL_MTCH_KEY, A.TRAN_AM, B.JR_NAME, C.ERR_MSG 
  FROM TABLE1 A 
       LEFT JOIN TABLE2 B 
          ON (A.DTL_MTCH_KEY = B.DTL_MTCH_KEY) 
       LEFT JOIN TABLE3 C 
          ON (A.DTL_MTCH_KEY = C.DTL_MTCH_KEY 
              AND C.SYS_IND = 'Y') 
  WHERE DATE = '2022-05-26'
  </code></pre>
  <p>Thanks in Advance</p>