title: SQL nested query in SQL server
body: <p>i have a library database which wrote a query to display count of loaned books by employee like this:</p>
  
  <pre><code>select Emploee.[Emp-No],count(*)  as ecount
  from Emploee 
  inner join Loan on Emploee.[Emp-No]=Loan.[Emp-No]
  inner join Book on Loan.ISBN=Book.ISBN group by Emploee.[Emp-No] 
  </code></pre>
  
  <p>the result of above query is something like this:</p>
  
  <pre><code>Emp-No    ecount
  ------------------
  1000      4
  1001      2
  1002      3
  </code></pre>
  
  <p>now i want to modify the output and make a comparison between ecount column of each row of result with another query which give me count of loaned books based on specific published by that user 
  in other word the result im looking for is something like this</p>
  
  <pre><code>Emp-No    ecount     
  -----------------
  1000      4             
  </code></pre>
  
  <p>assume Employee 1000 loaned all of his book from one publisher. he will be showen in the result.</p>
  
  <p>something like this</p>
  
  <pre><code> "..... my query...." having ecount= 
       (select count(*) from books where publisher='A')
  </code></pre>
  
  <p>but i cant use the result ecount in another query :(</p>