title: What is the difference between GROUP BY and DISTINCT?
body: <p>I have the table with the following data</p>
  
  <pre><code>empid   empname deptid   address
  --------------------------------
  aa76    John     6       34567
  aa75    rob      4       23456
  aa71    smith    3       12345
  aa74    dave     2       12345
  a77     blake    2       12345
  aa73    andrew   3       12345
  aa90    sam      1       12345
  aa72    will     6       34567
  aa70    rahul    5       34567
  </code></pre>
  
  <p>I've used the following queries:</p>
  
  <pre><code>select deptid, EMPID ,EMPNAME ,ADDRESS
  from mytable
  group by 1,2,3,4
  </code></pre>
  
  <p>Which gives the result:</p>
  
  <pre><code>deptid  empid  empname address
  ------------------------------
  1       aa90   sam      12345
  2       aa74   dave     12345
  2       aa77   blake    12345
  3       aa71   smith    12345
  3       aa73   andrew   12345
  4       aa75   rob      23456
  5       aa70   rahul    34567
  6       aa76   John     34567
  6       aa72   will     34567
  </code></pre>
  
  <p>And for the query:</p>
  
  <pre><code>select distinct (deptid),EMPID,EMPNAME,ADDRESS
  from mytable
  </code></pre>
  
  <p>The result set is:</p>
  
  <pre><code>deptid empid empname address   
  ----------------------------
  1      aa90  sam     12345
  2      aa74  dave    12345
  2      aa77  blake   12345
  3      aa71  smith   12345
  3      aa73  andrew  12345
  4      aa75  rob     23456
  5      aa70  rahul   34567
  6      aa72  will    34567
  6      aa76  John    34567
  </code></pre>
  
  <p>In the second query though I've given <code>DISTINCT</code> for DEPTID, how come I got the duplicate DEPTID...</p>
  
  <p>Could you explain this?</p>