title: how to get count in sql server while using inner joins?
body: <p>I have following query:</p>
  
  <pre><code>SELECT  
     h.helpcontent, s.MenuID, s.pkSitePageId, s.PageAliasName,
     s.SitePageName,s.pagepath
  FROM 
     tblSiteRolePermissions p
  INNER JOIN 
     tblSitePages s ON p.fkSitePageId = s.pkSitePageId
  INNER JOIN 
     tblHelp h ON s.pkSitePageId=h.fkSitePageId
  WHERE 
     (p.fkRoleId = 4 AND p.ViewOnly = 1) 
  ORDER BY 
     s.pkSitePageId
  </code></pre>
  
  <p>I want to get count from <code>tblSiteRolePermissions</code>. I have tried the <code>Count</code> but its throwing some error like:</p>
  
  <blockquote>
    <p><em>Msg 8120, Level 16, State 1, Line 1<br>
    Column 'tblHelp.HelpContent' is invalid in the select list because it is not contained in  either an aggregate function or the GROUP BY clause.</em></p>
  </blockquote>
  
  <p>Please help me and let me know where I am wrong.</p>
  
  <p><strong>Update</strong></p>
  
  <p>Here is the code I am trying:</p>
  
  <pre><code>SELECT 
      count(p.pkRolePermissionId), 
      h.helpcontent, s.MenuID, s.pkSitePageId, s.PageAliasName, 
      s.SitePageName, s.pagepath
  FROM
      tblSiteRolePermissions p
  INNER JOIN 
      tblSitePages s ON p.fkSitePageId = s.pkSitePageId
  INNER JOIN
      tblHelp h ON s.pkSitePageId = h.fkSitePageId
  WHERE 
      (p.fkRoleId = 4 AND p.ViewOnly = 1) 
  ORDER BY 
      s.pkSitePageId
  </code></pre>