title: Select Count Top Inner Join and Where Clause in SQL
body: <p>This is my Query:</p>
  
  <pre><code>SELECT TOP 3 tablestudentanswer.examid, 
               tablestudentanswer.studentid, 
               tablestudentanswer.itemno, 
               tablestudentanswer.studentanswer, 
               tablescore.score 
  FROM   tablestudentanswer 
         INNER JOIN tablescore 
                 ON tablestudentanswer.studentid = tablescore.studentid 
                    AND tablestudentanswer.examid = tablescore.examid 
  WHERE  tablestudentanswer.examid = 1 
         AND tablestudentanswer.itemno = 1 
  ORDER  BY tablescore.score ASC 
  </code></pre>
  
  <p>It returns this table:</p>
  
  <pre><code>ExamID  StudentID  ItemNo  StudentAnswer   Score
  1006    1          1       A               25
  1005    1          2       B               30
  1004    1          3       A               35
  </code></pre>
  
  <p>What i want to do is it will return 2 if StudentAnswer='A' and 1 if StudentAnswer='B'
  Guys there is nothing wrong with my query on top. What i am asking is what should I add in that query.</p>
  
  <p>I have this which  in my mind should return 2 but its an error.</p>
  
  <pre><code>Select COUNT(*) From (
  Select Top 3 TableStudentAnswer.ExamID, TableStudentAnswer.StudentID, TableStudentAnswer.ItemNo, TableStudentAnswer.StudentAnswer, TableScore.Score 
  from TableStudentAnswer
  Inner join TableScore on TableStudentAnswer.StudentID=TableScore.StudentID and TableStudentAnswer.ExamID=TableScore.ExamID
  where TableStudentAnswer.ExamID=1 and TableStudentAnswer.ItemNo=1
  Order By TableScore.Score Asc) where TableStudentAnswer.StudentAnswer = 'A' 
  </code></pre>
  
  <p>It should return:</p>
  
  <pre><code>2
  </code></pre>
  
  <p>Please help me!</p>