title: Query returning duplicate rows
body: <p>I wrote this query</p>
  
  <pre><code>SELECT DISTINCT 
      F2_FILIAL, F2_SERIE, F2_DOC, 
      C6_NUM, AB7_NUMOS, A1_NOME, F2_EMISSAO, F2_VALBRUT, F2_VEND1, 
      A3_NOME,F2_COND , E4_DESCRI, C5_NATUREZ, ED_DESCRIC, AAG_DESCRI
  FROM 
      SF2010 SF 
  LEFT JOIN 
      SE4010 SE ON F2_COND = E4_CODIGO 
  LEFT JOIN 
      SA3010 A3 ON F2_VEND1 = A3_COD 
  LEFT JOIN 
      SA1010 A1 ON F2_CLIENTE = A1_COD 
  LEFT JOIN 
      SD2010 SD ON F2_DOC = D2_DOC 
  LEFT JOIN 
      SC6010 C6 ON D2_PEDIDO = C6_NUM 
  LEFT JOIN 
      SC5010 C5 ON D2_PEDIDO = C5_NUM 
  LEFT JOIN 
      SED010 ED ON C5_NATUREZ = ED_CODIGO 
  LEFT JOIN 
      AB7010 AB ON SUBSTRING(C6_NUMOS,1,6) = AB7_NUMOS 
  LEFT JOIN 
      AAG010 AG ON AB7_CODPRB = AAG_CODPRB 
  WHERE 
      (F2_CLIENTE &gt;= '      ' 
       AND F2_CLIENTE &lt;= 'zzzzzz') 
      AND (F2_EMISSAO &gt;= '20170222'
           AND F2_EMISSAO &lt;= '20170222')
      AND (F2_VEND1 &gt;= '' 
           AND F2_VEND1 &lt;= 'zz') 
      AND (C5_NATUREZ &gt;= '' 
           AND C5_NATUREZ &lt;= 'zzzzzzzzzz') 
      AND (F2_COND &gt;= '' 
           AND F2_COND &lt;= 'zzz') 
      AND (F2_FILIAL &gt;= '' 
           AND F2_FILIAL &lt;= 'zz') 
      AND (SF.D_E_L_E_T_ &lt;&gt; '*') 
      AND F2_DUPL &lt;&gt; '' 
      AND F2_VALFAT &lt;&gt; 0 
  ORDER BY 
      F2_VEND1, F2_EMISSAO
  </code></pre>
  
  <p>And it results in something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/2BGrS.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2BGrS.jpg" alt="query result"></a></p>
  
  <p>Notice that the 2 last rows are the same (the main field here is F2_DOC, it should never appear twice), but since the field C6_NUM and AB7_NUMOS has more than one reference it displays both of them, duplicating the row.</p>
  
  <p>How can I improve my query to not duplicate a row when the table I'm joining has more than 1 distinct FK to the table I'm querying?</p>