Question
Given the following SQL query: SELECT department
_ id, COUNT(*) AS employee _ count FROM employees GROUP BY department_id HAVING COUNT(*) > 5; What is the purpose of the HAVING clause in this query?Solution
The HAVING clause is used in SQL to filter groups created by the GROUP BY clause based on an aggregate function. 1. Aggregate Filtering: Unlike the WHERE clause, which filters rows before grouping, HAVING applies conditions on grouped data. 2. Purpose in Query: In this query, the HAVING clause ensures that only those departments with more than 5 employees (as determined by COUNT(*)) are included in the result set. 3. Execution Process: o The GROUP BY groups the data by department_id. o The COUNT(*) calculates the number of employees in each department. o The HAVING clause filters out groups where COUNT(*) is less than or equal to 5. This differentiation between WHERE and HAVING is crucial for effective data querying. Why Other Options Are Incorrect: • A) To filter rows before grouping them: The WHERE clause performs pre-grouping filtering, not HAVING. • C) To apply a condition to the entire table: HAVING only applies conditions to grouped results. • D) To apply conditions only to the COUNT(*) function: While COUNT(*) is used, the HAVING clause applies to groups as a whole. • E) To sort the rows by department_id: Sorting is achieved using the ORDER BY clause, not HAVING.
How long has SEBI banned First Overseas Capital from participating in the securities market?Â
Which ministry has set up the Bhartiya Beej Sahkari Samiti Limited (BBSSL)?
Padma Vibhushan awardee Somanahalli Mallaiah Krishna, who passed away in December 2024, was the former Chief Minister of _________.
According to the World Gold Council (WGC), which country was the largest buyer of gold in 2024?
National Fish Farmers Day 2025 commemorates which key breakthrough in Indian aquaculture?Â
Who became the First Vice President of the Federal Reserve Bank, New York?Â
- Netumbo Nandi-Ndaitwah became the first woman president of which country in 2025?
What significant defence equipment is set to be retired by the Indian Air Force on 19th September 2025?Â
- Under the PM-AASHA scheme, which agency is responsible for procurement of pulses and oilseeds if market prices fall below MSP?
Recently the Election Commission of India is hosting a two-day international conference on the theme ‘Role, Framework & Capacity of Election Manageme...