title: Multi SELECT SQL statement
body: <p>Writing my first nested <code>SELECT</code> statement and I'm hoping someone can help me out. </p>
  
  <p>I need to grab the <code>CompanyCode</code> and <code>AgentId</code> from the <code>UniqueAgentIdtoUniqueAgentId</code> table. However, I only need the ones that show up in a query from another table. The common link between the rows will the the <code>UniqueAgentId</code> column (basically I need to grab the <code>CompanyCode</code> and <code>AgentId</code> from the rows that contain the same <code>UniqueAgentId</code> as come up in the nested query).</p>
  
  <p>When I write this query out, I get the extremely helpful message </p>
  
  <blockquote>
    <p>Incorrect syntax near ')'</p>
  </blockquote>
  
  <p>Query:</p>
  
  <pre><code>SELECT 
      CompanyCode, AgentId
  FROM 
      UniqueAgentIdToUniqueAgentId un
  WHERE 
      un.UniqueAgentId = 
         (SELECT UniqueAgentId 
          FROM 
              (SELECT q.LastChangeDate, a.UniqueAgentId 
               FROM QueueUpdates q, AgentProductTraining a 
               WHERE a.LastChangeDate &gt;= q.LastChangeDate)
         )
  </code></pre>
  
  <p>EDIT 
  Thank you very much for the responses. Using every single query below, however I keep getting the same error message: Invalid object name 'UniqueAgentIdToUniqueAgentId'. This is odd to me because this is an actual table on the database that SQL Management Studio can see. </p>
  
  <p>SECOND EDIT
  This turned out to simply be a spelling error. The new error is "The conversion of the varchar value '3030111101' overflowed an int column." Not quite sure what this means either...</p>
  
  <p>FINAL EDIT
  I was attempting to compare a char with an it, which caused this error. Thanks again for all the help!</p>