title: How to use group by in SQL Server query?
body: <p>I have problem with group by in SQL Server</p>
  
  <p>I have this simple SQL statement:</p>
  
  <pre><code>select * 
  from Factors 
  group by moshtari_ID
  </code></pre>
  
  <p>and I get this error :</p>
  
  <blockquote>
    <p>Msg 8120, Level 16, State 1, Line 1<br>
    Column 'Factors.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</p>
  </blockquote>
  
  <p>This is my result without group by :</p>
  
  <p><a href="https://i.stack.imgur.com/VmuTK.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/VmuTK.jpg" alt="enter image description here"></a></p>
  
  <p>and this is error with group by command :</p>
  
  <p><a href="https://i.stack.imgur.com/Dcqxz.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/Dcqxz.jpg" alt="enter image description here"></a></p>
  
  <p>Where is my problem ?</p>