title: Inner Join Results in TSQL
body: <p>I have three tables that I am working with and I am having trouble getting just what I need. </p>
  
  <p>The tables are called Documents, Variable, and VariableValue. Documents has a primary key DocumentID, VariableValue and Variable has as primary key VariableID and VariableValue also has DocumentID as a primary key. The following query gives very close to what I need. Additionally it controls the return of versions of a file to the latest one.</p>
  
  <pre><code>Select Distinct vv.ValueCache as 'Company Name'
  from VariableValue vv, Documents d
  where d.DocumentID = vv.DocumentID and
  vv.VariableID =  (Select VariableID
                     from Variable
                     where  VariableName  = 'Supplier Type' and d.Deleted = 0) and 
  vv.RevisionNo = (Select Max( Vv1.RevisionNo)
                    From VariableValue vv1 
                    where vv1.VariableID = vv.VariableID and
                          vv1.DocumentID = d.DocumentID and
                          vv1.ValueText is not null)  and
  vv.ValueCache != ''
  </code></pre>
  
  <p>What I really want to get is a list of files in which a column called 'Supplier Type' (called out in Variable table) does <strong>not</strong> have the value 'Distributor' contained in the VariableValues.ValueText column. I feel like I am very close, I just can't figure out how to get the Distributor argument in the call. </p>