All Exams Test series for 1 year @ ₹349 only
Question

Consider the following relation :

Works (emp_name, company_name, salary)

Here, emp_name is primary key.

Consider the following SQL query

    Select emp_name

    From works T

    where salary > (select avg (salary)

                    from works S

                    where T.company _ name =

                        S.company _ name)

The above query is for following :

This question was previously asked in
UGC NET 2016 Paper 1 Question Paper (10-Jul-2016)
The correct answer is

Find all employees who earn more than the average salary of all employees of their company.

The query uses a correlated subquery: the inner query refers to T, the tuple variable of the outer query, so it is re-evaluated for every row of the outer relation.

Step 1 — For a given outer row T, the inner query computes avg(salary) over all rows S of works with S.company_name = T.company_name, i.e. the average salary of the employees of T's own company.

Step 2 — The outer WHERE keeps row T if T.salary is greater than that company-wise average, and SELECT returns T.emp_name. No MAX or ordering is applied, so every qualifying employee is returned, not just one.

Step 3 — The result is therefore the set of all employees whose salary exceeds the average salary of their own company.

Descriptions that speak of 'the highest paid employee' are wrong because nothing restricts the result to a single top earner. Descriptions comparing with the average over all companies would need an uncorrelated subquery (select avg(salary) from works) without the company-name condition.

Find all employees who earn more than the average salary of all employees of their company. option is correct.

Was this answer helpful?

Similar Questions

  1. Consider the following three SQL queries (Assume the data in the people table) :

    (a) Select Name from people where Age>21;

    (b) Select Name from people where Height>180;

    (c) Select Name from people where (Age>21) or (Height>180);

    If the SQL queries (a) and (b) above, return 10 rows and 7 rows in the result set respectively, then what is one possible number of rows returned by the SQL query (c) ?

  2. Suppose ORACLE relation R(A, B) currently has tuples {(1, 2), (1, 3), (3, 4)} and relation S(B, C) currently has {(2, 5), (4, 6), (7, 8)}. Consider the following two SQL queries SQ1 and SQ2 :

    SQ1 : Select *

        From R Full Join S

        On R.B = S.B;

    SQ2 : Select *

        From R Inner Join S

        On R.B = S.B;

    The numbers of tuples in the result of the SQL query SQ1 and the SQL query SQ2 are given by :

  3. Consider a “CUSTOMERS” database table having a column “CITY” filled with all the names of Indian cities (in capital letters). The SQL statement that finds all cities that have “GAR” somewhere in its name, is :

  4. The STUDENT information in a university stored in the relation STUDENT (Name, SEX, Marks, DEPT_Name)

    Consider the following SQL Query SELECT DEPT_Name from STUDENT where SEX = ‘M’ group by DEPT_Name having avg (Marks)>SELECT avg (Marks) from STUDENT. It Returns the Name of the Department for which :

  5. An Assertion is a predicate expressing a condition we wish database to always satisfy. The correct syntax for Assertion is :

  6. Match the following :

    List - IList - II
    a. DDLi. LOCK TABLE
    b. DMLii. COMMIT
    c. TCLiii. Natural Difference
    d. BINARY Operationiv. REVOKE

    Codes :

  7. Given query:

    select s.rollno, s.name

    from student s

    where EXISTS (select c.courseid from course c Where c.deptno=5 and

    EXISTS (select e.* from enrollemnt e

    where e.courseid = c.courseid and

    e.rollno = s.rollno));

    Which one of the following statements is correct with respect to the given query?

  8. Which of the following queries would retrieve the dept id and name of all the departments that are such that the total of the credits of all the offered courses by the department is strictly greater than 40?

  9. Which of the following queries would compute, for each department, the total credits of all the courses offered by the department?

  10. Given query: select s.rollno from students where s.sex = ALL (select f.sex from professor f where f.empid = s.advisor)

    Consider the following statements about the given query that retrieves the set of all students whose gender is same as the gender of their advisor:

    S1. It has a correlated subquery

    S2. It has an uncorrelated subquery

    S3. If we replace ALL by ANY in the above query, its result will be different

    S4. If we replace ALL by ANY in the above query, its result will be same.

    Identify all the statement that are TRUE:


Important Questions from SQL

  1. Match the following -

    List IList II
    (a)DDL(i)LOCK TABLE
    (b)DML(ii)COMMIT
    (c)TCL(iii)Natural Difference
    (d)Binary operation(iv)REVOKE
  2. Which of the following is NOT a Structured Query Language Data type?

  3. Consider a table Employee(EmpID, TeamID), where the column EmpID (ID of an employee) is the primary key. The column TeamID denotes the team ID of the team of which the employee is a member. TeamID is a NOT NULL column.

    We want to display the size of the team (denoted as TeamSize) in which each employee is a member by using SQL. As an example, the desired output for the given Employee table is also shown in tabular form.

    Which of the following is/are correct?

    Employee
     

    EmpIDTeamID
    18
    28
    38
    47
    57
    69



    Output
     

    EmpIDTeamSize
    13
    23
    33
    42
    52
    61
  4. Let Account be a relation as shown. 

                                                                                                             Account

    AccNoBalance
    A15000
    A25000
    A310000
    A415000
    A518000

    Consider the given SQL query.

    SELECT AccNo FROM Account AS A 

    WHERE (SELECT COUNT(*) FROM Account AS B  

    WHERE A.Balance < B.Balance) >= (SELECT COUNT(*)  

    FROM Account AS C WHERE A.Balance > C.Balance)

    The number of rows returned by the SQL query is __________ . (Answer in integer)

  5. Consider the following two tables named Raider and Team in a relational database maintained by a Kabaddi league. The attribute ID in table Team references the primary key of the Raider table, ID.

    Raider
    IDNameRaidsRaidPoints
    1Arjun200250
    2Ankush190219
    3Sunil150200
    4Reza150190
    5Pratham175220
    6Gopal193215
    Team
    CityIDBidPoints
    Jaipur2200
    Patna3195
    Hyderabad5175
    Jaipur1250
    Patna4200
    Jaipur6200

    The SQL query described below is executed on this database: 

    SELECT * 

    FROM Raider, Team 

    WHERE Raider.ID=Team.ID AND City="Jaipur" AND 

    RaidPoints > 200; 

    The number of rows returned by this query is ________.

Need Expert Advice?
Upcoming Exams
CTET
December 12, 2026
Test Series
UGC NET img
Teaching
UGC NET (Paper 2) 2026 Mock Test Series
796 Tests 2 Tests Free
4.4(39)
English
More Questions from UGC NET

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App