arrow
arrow
arrow
Which of the following is true about the HAVING clause?
Question



Which of the following is true about the HAVING clause?

A.

Similar to the WHERE clause but is used for columns rather than groups

B.

Similar to WHERE clause but is used for rows rather than columns

C.

Similar to WHERE clause but is used for groups rather than rows

D.

More than one of the above

E.

None of the above

Correct option is C


In SQL, the HAVING clause is used to filter grouped data after the GROUP BY operation. It is similar to the WHERE clause but applies to aggregated results rather than individual rows.
Important Key Points:
1. Difference Between WHERE and HAVING:
· WHERE is used to filter rows before aggregation (works on individual records).
· HAVING is used to filter groups after aggregation (works on grouped records).
2. Correct Example of HAVING:
SELECT department, AVG(salary)
FROM employees
GROUP BY department
HAVING AVG(salary) > 50000;
· This query first groups employees by department, calculates the average salary, and then filters out departments where the average salary is greater than 50000 using HAVING.
2. Why Option (c) is Correct?
· HAVING filters groups rather than individual rows.
· WHERE filters rows before grouping, while HAVING filters groups after aggregation.
Knowledge Booster:
· WHERE filters before GROUP BY, HAVING filters after GROUP BY.
· HAVING is used with aggregate functions (COUNT(), SUM(), AVG(), etc.), while WHERE works with individual records.
· HAVING can be combined with WHERE:
SELECT department, COUNT(*)
FROM employees
WHERE salary > 30000
GROUP BY department
HAVING COUNT(*) > 10;
· Here, WHERE filters rows with salary > 30,000 before grouping.
· HAVING filters groups where employee count > 10 after aggregation.
· (a) Similar to the WHERE clause but is used for columns rather than groups → ❌ Incorrect because HAVING is used for groups, not columns.
· (b) Similar to WHERE clause but is used for rows rather than columns → ❌ Incorrect because HAVING applies to groups, not individual rows.

Free Tests

Free
Must Attempt

UPTET Paper 1: PYP Held on 23rd Jan 2022 (Shift 1)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Social Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET Paper 2 Maths & Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
test-prime-package

Access ‘BPSC TRE (11-12)’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
354k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow