title: Transact-SQL - sub query or left-join?
body: <p>I have two tables containing Tasks and Notes, and want to retrieve a list of tasks with the number of associated notes for each one. These two queries do the job:</p>
  
  <pre>select t.TaskId,
         (select count(n.TaskNoteId) from TaskNote n where n.TaskId = t.TaskId) 'Notes'
  from   Task t
  
  -- or
  select t.TaskId,
         count(n.TaskNoteId) 'Notes'
  from   Task t
  left join
         TaskNote n
  on     t.TaskId = n.TaskId
  group by t.TaskId</pre>
  
  <p>Is there a difference between them and should I be using one over the other, or are they just two ways of doing the same job? Thanks.</p>