Bird
0
0

You have this view:

medium📝 Debug Q14 of 15
SQL - Views
You have this view:
CREATE VIEW dept_count AS SELECT department, COUNT(*) AS emp_count FROM employees GROUP BY department;

Which query will cause an error when run on this view?
ASELECT department FROM dept_count;
BSELECT department, salary FROM dept_count;
CSELECT emp_count FROM dept_count WHERE department = 'Sales';
DSELECT * FROM dept_count WHERE emp_count > 5;
Step-by-Step Solution
Solution:
  1. Step 1: Identify columns in the view

    The view has columns: department and emp_count only.
  2. Step 2: Check each query's column usage

    SELECT department, salary FROM dept_count; tries to select 'salary' which does not exist in the view, causing an error.
  3. Final Answer:

    SELECT department, salary FROM dept_count; causes error -> Option B
  4. Quick Check:

    Querying non-existent column = error [OK]
Quick Trick: Select only columns defined in the view [OK]
Common Mistakes:
MISTAKES
  • Selecting columns not in the view
  • Assuming all original table columns exist in view
  • Ignoring GROUP BY effects on columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes