title: Regarding SQL Inner Join
body: <p>The question is as follows :</p>
  <p>My question is regarding SQL code for the following question.</p>
  <p>Final query should return the vendor information along with the values from the table cb_vendorinformation.</p>
  <p>You should combine the values of the two tables based on the GroupID column.</p>
  <p>The final query should only print out the GroupID, CompanyName, and final count of all rows that are grouped into each company name under a column titled Count.</p>
  <p>The output table should be then sorted by the Count column and then sorted by GroupID so that a higher number appears first.</p>
  <p>This is the main table :</p>
  <p><img src="https://i.stack.imgur.com/aaSVe.png" alt="maintable" /></p>
  <p>The output should look like this :</p>
  <p><img src="https://i.stack.imgur.com/XDRDl.png" alt="finaloutput" /></p>
  <p>I could develop a code as follows but I am not getting the correct output :</p>
  <pre><code>SELECT m.GroupID, c.CompanyName, Count(*) as count
  FROM maintable_KN01N m
    INNER JOIN cb_vendorinformation c  ON m.GroupID = c.GroupID
  </code></pre>
  <p>My output :</p>
  <p><img src="https://i.stack.imgur.com/hgWh9.png" alt="my output" /></p>
  <p>Expected output :</p>
  <p><img src="https://i.stack.imgur.com/4ijDl.png" alt="expected output" /></p>
  <p>Could someone please help me out here ?</p>
  <p>I tried this code :</p>
  <pre><code>SELECT m.GroupID
       , c.CompanyName
       , Count(*) as count 
    FROM maintable_KN01N m 
    JOIN cb_vendorinformation c  
      ON m.GroupID = c.GroupID 
   GROUP 
      BY m.GroupID
       , c.CompanyName;
  </code></pre>
  <p>And was getting the output as follows :</p>
  <p><a href="https://i.stack.imgur.com/UCVmo.png" rel="nofollow noreferrer">Output2</a></p>