title: SQL GROUP BY - Using COUNT() function
body: <p>I've been doing a task which involves creating a database for a hospital and I've been encountering a very frustrating error which I cannot seem to fix no matter how much research that I do.</p>
  
  <p>The error I received is:</p>
  
  <blockquote>
    <p>ERROR at line 1: ORA-00979: not a GROUP BY expression</p>
  </blockquote>
  
  <p>The structure of my code for inserting the values is:</p>
  
  <pre><code>SELECT  CONSULTANT.S_NO, DOCTOR.D_NAME, CONSULTANT.SPEC, 
  PATIENT.P_ID, PATIENT.P_NAME, COUNT(CONSULTANT.P_ID)
  FROM    PATIENT, CONSULTANT, DOCTOR                            
  WHERE   PATIENT.P_ID = CONSULTANT.P_ID
  AND     CONSULTANT.S_NO = DOCTOR.S_NO
  GROUP BY CONSULTANT.S_NO;
  </code></pre>
  
  <p>And the structure of my tables are:</p>
  
  <pre><code>    CREATE TABLE PATIENT (
      P_ID        NUMBER NOT NULL,
      P_NAME      CHAR(20),
      ADDRESS     VARCHAR(20),
      DOB     DATE,
      WARD_NO     NUMBER NOT NULL, 
      C_S_NO      NUMBER NOT NULL,
      CONSTRAINT PK_PATIENT PRIMARY KEY(P_ID)
  );
  
  CREATE TABLE DOCTOR (
      S_NO        NUMBER NOT NULL,
      D_NAME      CHAR(20),
      APP_DATE    DATE,
      CONSTRAINT PK_DOC PRIMARY KEY(S_NO)
  );
  
  CREATE TABLE CONSULTANT (
      S_NO        NUMBER NOT NULL,
      P_ID        NUMBER NOT NULL,
      SPEC        CHAR(20),
      T_CODE      VARCHAR(20) NOT NULL,
      CONSTRAINT PK_CDOC PRIMARY KEY(S_NO)
  );
  </code></pre>
  
  <p>Would really appreciate any help anyone could give me on solving this dilemma.</p>