📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store

    • Question

      In SQL, what is the difference between 'WHERE' and

      'HAVING' clauses?
      A WHERE filters columns; HAVING filters rows Correct Answer Incorrect Answer
      B WHERE is used with JOIN; HAVING is used with subqueries Correct Answer Incorrect Answer
      C WHERE filters rows before grouping; HAVING filters groups after GROUP BY Correct Answer Incorrect Answer
      D WHERE can use aggregate functions; HAVING cannot Correct Answer Incorrect Answer
      E There is no difference — both filter rows identically Correct Answer Incorrect Answer

      Solution

      WHERE applies to individual rows before GROUP BY processing and cannot use aggregate functions. HAVING applies after GROUP BY to filter entire groups and can use aggregate functions. Example in banking: SELECT BranchID, COUNT() AS TotalAccounts FROM Accounts WHERE Status='Active' GROUP BY BranchID HAVING COUNT() > 500 — this first filters only active accounts (WHERE), groups by branch, then shows only branches with more than 500 active accounts (HAVING).

      Practice Next

      Relevant for Exams:

      ask-question