UGC-NET Oct 2020 · SQL Queries

MCQ · 2 marks · Problem DBMS-SQL-0022

Consider the following table structures related to a university for the below question. EMPLOYEE
    NAME VARCHAR (30) NOT NULL,
    EID VARCHAR (10) NOT NULL,
    DEPTNO INT (5) NOT NULL,
    HODEID VARCHAR (10),
    SALARY INT (10),
PRIMARY KEY (EID),
FOREIGN KEY (HODEID) REFERENCES EMPLOYEE (EID),
FOREIGN KEY (DEPTNO) REFERENCES DEPARTMENT (DID);
DEPARTMENT
    DID INT (5) NOT NULL,
    DNAME VARCHAR(30) NOT NULL,
    HODID VARCHAR (10) NOT NULL,
    HODNAME VARCHAR (30),
PRIMARY KEY (DID),
UNIQUE (DNAME),
FOREIGN KEY (HODID) REFERENCES EMPLOYEE (EID)
PROJECT WORK:
    EMPID VARCHAR (10) NOTNULL,
    PROJNO INT(5) NOT NULL,
    PROJECTLOC VARCHAR (30) NOT NULL,
PRIMARY KEY (EMPID, PROJNO),
FOREIGN KEY (EMPID) REFERENCES EMPLOYEE (EID),
Given below are two statements to find the sum of salaries of all employees of the English department as well as the maximum, minimum and average salary in English department STATEMENT $I$:
SELECT SUM (SALARY) MAX(SALARY) MIN(SALARY),
AVG (SALARY) FROM EMPLOYEE, DEPARTMENT
WHERE DEPTNO=DID AND DNAME=’ENGLISH’
STATEMENT $II$:
SELECT SUM (SALARY), MAX(SALARY), MIN (SALARY),
AVG (SALARY), FROM EMPLOYEE, DEPARTMENT
WHERE DNAME=’ENGLISH’
In the light of the above statements, choose the correct answer from the options given below:
  1. A
    Both Statement $I$ and Statement $II$ are true
  2. B
    Both Statement $I$ and Statement $II$ are false
  3. C
    Statement $I$ is correct but Statement $II$ is false
  4. D
    Statement $I$ is incorrect but Statement $II$ is true

Solve it on GATE DA practice →More Relational Model & SQL problems

Show the worked solutionStatement I joins EMPLOYEE and DEPARTMENT with the join condition DEPTNO = DID and keeps only DNAME = 'ENGLISH'. The aggregates therefore cover exactly the English department's employees. This is the intended correct query (the missing comma after SUM(SALARY) is a typesetting slip). Statement II has no join condition. EMPLOYEE \(\times\) DEPARTMENT filtered on DNAME = 'ENGLISH' pairs every employee of every department with the English row, so the sum, max, min and average are over all employees. It also has a stray comma before FROM. It is false.Answer: C

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com