title: SQL Server Query returning duplicate rows
body: <p>I have a query of SQL that is a join of multiple tables, it is returning duplicate rows and after hours of going through it can't find out where its going wrong</p>
  
  <pre><code>SELECT 
      StkItem.iUOMStockingUnitID, 
      _etblUnits1.cUnitCode as 'parkSize', 
      _etblUnits2.cUnitCode as 'quantitySize', 
      InvNum.fInvTotExclForeign, 
      [_btblInvoiceLines].*, 
      [_rtblCountry].cCountryName, 
      [CurrencyHist].fBuyRate, 
      Vendor.Name, 
      InvNum.OrderDate, 
      InvNum.InvNumber 
  FROM
      [dbo].[_btblInvoiceLines] 
  LEFT JOIN 
      StkItem ON StkItem.StockLink = [_btblInvoiceLines].iStockCodeID 
  LEFT JOIN 
      _etblUnits as _etblUnits1 ON _etblUnits1.idunits = StkItem.iUOMDefSellUnitID 
  LEFT JOIN 
      _etblUnits as _etblUnits2 ON _etblUnits2.idunits = StkItem.iUOMStockingUnitID 
  LEFT JOIN 
      InvNum ON iInvoiceID = AutoIndex 
  LEFT JOIN 
      Vendor ON Vendor.DCLink = InvNum.AccountID 
  LEFT JOIN 
      [_rtblCountry] ON [_rtblCountry].idCountry = Vendor.iCountryID   
  LEFT JOIN 
      [CurrencyHist] ON InvNum.ForeignCurrencyID = [CurrencyHist].iCurrencyID 
  WHERE 
      OrderNum = '' 
      AND [CurrencyHist].iCurrencyID = (SELECT TOP 1 iCurrencyID 
                                        FROM [CurrencyHist] 
                                        WHERE iCurrencyID = InvNum.ForeignCurrencyID 
                                        ORDER BY idCurrencyHist DESC)
  </code></pre>
  
  <p>Here is the query, any help will be highly appreciated, thanks in advance</p>