title: Query performance tuning of SQL Server
body: <p>I have two tables:</p>
  
  <pre><code>SELECT [DealerdistributionId]
        ,[DealerCode]
        ,[BarCode]
        ,[BarCode2]
        ,[Model]
        ,[DONumber]
        ,[DistributionDate]
    FROM [tblDealerDistributionDetails]
  </code></pre>
  
  <p>yields these results</p>
  
  <p><a href="https://i.stack.imgur.com/a2CKK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a2CKK.png" alt="enter image description here"></a></p>
  
  <p>and another table:</p>
  
  <pre><code>SELECT [ProductRegID]
        ,[ProductType]
        ,[ProductModelID]
        ,[SalerID]
        ,[ProductID]
        ,[PhoneNumber]
        ,[RegistrationDate]
    FROM [tblProductRegistration]
  </code></pre>
  
  <p>results</p>
  
  <p><a href="https://i.stack.imgur.com/oWCLq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oWCLq.png" alt="enter image description here"></a></p>
  
  <p>The second table <code>tblProductRegistration</code> logs <code>ProductID</code> from <code>BarCode</code> or <code>BarCode2</code> from the first table <code>tblDealerDistributionDetails</code>, but only one <code>BarCode</code> or <code>BarCode2</code>.</p>
  
  <p>I want to find which Dealer has what quantity of model with entry in tblProductRegistration.</p>
  
  <p>Output:
  DelarCode,Model,TotalEntry in tblProductRegistration.</p>
  
  <p>I have tried this</p>
  
  <pre><code>select DealerCode, COUNT(*) as [Activated]
   from  tblDealerDistributionDetails 
   where   
   ( BarCode in (select ProductID from tblProductRegistration where RegistrationDate &gt;='2016-03-01' and RegistrationDate &lt;='2016-03-02') 
   or 
   BarCode2 in (select ProductID from tblProductRegistration where RegistrationDate &gt;='2016-03-01' and RegistrationDate &lt;='2016-03-02') ) 
   and Model= 'Olvio L12' group by DealerCode
  </code></pre>
  
  <p>for a specific model 'Olvio L12' but it causes perfomance issue.I need faster query perfomance</p>
  
  <p>with faster query performance.Please help.</p>