CBSE Class 12
Informatics Practices
01 Querying and SQL Functions
50
Total
0
Attempted
0
Correct
0
Wrong
00:00:00
Q-1
How many rows are present in the STUDENT table?
Easy
SQL General
Sample Data
| RollNo | Name | Class |
|---|---|---|
| 1 | Amit | XII |
| 2 | Neha | XII |
| 3 | Ravi | XI |
Reference Code
SELECT COUNT(*) FROM STUDENT;
Answer: 3
Explanation: COUNT(*) returns the total number of rows in the table, which is 3.
Q-2
Which rows are selected by the following query?
Easy
SQL Query
Sample Data
| RollNo | Name | Marks |
|---|---|---|
| 1 | Amit | 85 |
| 2 | Neha | 65 |
| 3 | Ravi | 75 |
Reference Code
SELECT * FROM STUDENT WHERE Marks >= 75;
Answer: Amit and Ravi
Explanation: The WHERE clause selects rows with Marks greater than or equal to 75, which are Amit and Ravi.
Q-3
How many distinct classes are present in the table?
Easy
SQL Function
Sample Data
| RollNo | Class |
|---|---|
| 1 | XII |
| 2 | XII |
| 3 | XI |
Reference Code
SELECT COUNT(DISTINCT Class) FROM STUDENT;
Answer: 2
Explanation: There are two distinct values in the Class column: XI and XII.
Q-4
Which value will be returned by the query?
Easy
SQL Function
Sample Data
| RollNo | Marks |
|---|---|
| 1 | 60 |
| 2 | 80 |
| 3 | 70 |
Reference Code
SELECT MAX(Marks) FROM STUDENT;
Answer: 80
Explanation: MAX() returns the highest value in the Marks column, which is 80.
Q-5
How many rows are selected by the query?
Easy
SQL Query
Sample Data
| EmpID | Dept |
|---|---|
| 1 | IT |
| 2 | HR |
| 3 | IT |
Reference Code
SELECT * FROM EMP WHERE Dept = 'IT';
Answer: 2
Explanation: There are two employees whose department is IT.
Q-6
Which value is ignored by aggregate functions such as SUM and AVG?
Easy
SQL Aggregation
Answer: NULL
Explanation: Aggregate functions ignore NULL values during calculation.
Q-7
How many groups are formed by the query?
Easy
SQL Grouping
Sample Data
| EmpID | Dept |
|---|---|
| 1 | Sales |
| 2 | HR |
| 3 | Sales |
| 4 | HR |
Reference Code
SELECT Dept FROM EMP GROUP BY Dept;
Answer: 2
Explanation: There are two distinct department values: Sales and HR.
Q-8
Which clause is used to sort the result of a query?
Easy
SQL General
Answer: ORDER BY
Explanation: ORDER BY is used to sort query results.
Q-9
Which value will be returned by the query?
Easy
SQL Aggregation
Sample Data
| Num |
|---|
| 10 |
| 20 |
| 30 |
Reference Code
SELECT SUM(Num) FROM T;
Answer: 60
Explanation: SUM adds all numeric values: 10 + 20 + 30 = 60.
Q-10
Which clause is used to select rows based on a condition?
Easy
SQL Query
Answer: WHERE
Explanation: WHERE is used to filter rows based on conditions.
Q-11
Which classes will appear in the output of the query?
Medium
SQL Grouping
Sample Data
| RollNo | Class | Marks |
|---|---|---|
| 1 | XI | 55 |
| 2 | XI | 75 |
| 3 | XII | 80 |
| 4 | XII | 60 |
Reference Code
SELECT Class
FROM STUDENT
WHERE Marks >= 60
GROUP BY Class;
Answer: XI and XII
Explanation: WHERE filters rows first. Both XI and XII have at least one student with Marks ≥ 60.
Q-12
How many rows are counted by the aggregate function?
Medium
SQL Aggregation
Sample Data
| EmpID | Dept | Salary |
|---|---|---|
| 1 | IT | 40000 |
| 2 | IT | NULL |
| 3 | HR | 30000 |
| 4 | HR | 30000 |
Reference Code
SELECT COUNT(Salary) FROM EMP;
Answer: 3
Explanation: COUNT(column) ignores NULL values, so three non-NULL salaries are counted.
Q-13
How many groups are formed by the query?
Medium
SQL Grouping
Sample Data
| EmpID | Dept | Location |
|---|---|---|
| 1 | IT | Delhi |
| 2 | IT | Mumbai |
| 3 | HR | Delhi |
| 4 | HR | Delhi |
Reference Code
SELECT Dept, Location
FROM EMP
GROUP BY Dept, Location;
Answer: 3
Explanation: Distinct (Dept, Location) pairs are (IT, Delhi), (IT, Mumbai), and (HR, Delhi).
Q-14
Which departments satisfy the condition in the query?
Medium
SQL Aggregation
Sample Data
| EmpID | Dept | Salary |
|---|---|---|
| 1 | IT | 30000 |
| 2 | IT | 30000 |
| 3 | HR | 40000 |
Reference Code
SELECT Dept
FROM EMP
GROUP BY Dept
HAVING SUM(Salary) >= 60000;
Answer: IT only
Explanation: IT has a total salary of 60000, which satisfies the HAVING condition; HR does not.
Q-15
Which rows are excluded before grouping is applied?
Medium
SQL Query
Sample Data
| RollNo | Class | Marks |
|---|---|---|
| 1 | XI | 45 |
| 2 | XI | 65 |
| 3 | XII | 75 |
| 4 | XII | 55 |
Reference Code
SELECT Class, AVG(Marks)
FROM STUDENT
WHERE Marks >= 60
GROUP BY Class;
Answer: Marks < 60
Explanation: WHERE removes rows with Marks less than 60 before GROUP BY is applied.
Q-16
What value will be returned by the query?
Medium
SQL Function
Sample Data
| Value |
|---|
| 10 |
| 20 |
| NULL |
| 30 |
Reference Code
SELECT AVG(Value) FROM T;
Answer: 20
Explanation: AVG ignores NULL values, so (10 + 20 + 30) / 3 = 20.
Q-17
Which query correctly filters aggregated results?
Medium
SQL Error Analysis
Answer: GROUP BY Dept HAVING COUNT(*) > 1
Explanation: HAVING is used to apply conditions on grouped (aggregated) data.
Q-18
Which values are counted by COUNT(DISTINCT Dept)?
Medium
SQL Function
Sample Data
| EmpID | Dept |
|---|---|
| 1 | IT |
| 2 | IT |
| 3 | HR |
| 4 | HR |
Reference Code
SELECT COUNT(DISTINCT Dept) FROM EMP;
Answer: 2
Explanation: COUNT(DISTINCT Dept) counts unique department values: IT and HR.
Q-19
Which clause is evaluated after GROUP BY but before ORDER BY?
Medium
SQL General
Answer: HAVING
Explanation: HAVING is evaluated after GROUP BY and before ORDER BY.
Q-20
Which query will result in a syntax error?
Medium
SQL Error Analysis
Answer: SELECT Class, Marks FROM STUDENT GROUP BY Class
Explanation: Marks is neither aggregated nor included in GROUP BY, causing a syntax error.
Q-21
Which departments will appear in the output?
Hard
SQL Grouping
Sample Data
| EmpID | Dept | Salary |
|---|---|---|
| 1 | IT | 50000 |
| 2 | IT | 20000 |
| 3 | HR | 30000 |
| 4 | HR | 30000 |
Reference Code
SELECT Dept
FROM EMP
WHERE Salary >= 30000
GROUP BY Dept
HAVING COUNT(*) > 1;
Answer: HR only
Explanation: WHERE keeps rows with Salary ≥ 30000. HR has two such rows, IT has only one. HAVING COUNT(*) > 1 keeps only HR.
Q-22
How many rows will be returned by the query?
Hard
SQL Aggregation
Sample Data
| RollNo | Class | Marks |
|---|---|---|
| 1 | XII | 80 |
| 2 | XII | 60 |
| 3 | XII | 40 |
| 4 | XI | 90 |
Reference Code
SELECT Class, COUNT(*)
FROM STUDENT
WHERE Marks >= 50
GROUP BY Class
HAVING COUNT(*) >= 2;
Answer: 0
Explanation: After WHERE, Class XII has two rows, Class XI has one. HAVING COUNT(*) ≥ 2 keeps only Class XII, producing one row.
Q-23
Which value will be returned by the query?
Hard
SQL Function
Sample Data
| Value |
|---|
| 10 |
| 10 |
| 20 |
| NULL |
Reference Code
SELECT AVG(DISTINCT Value) FROM T;
Answer: 15
Explanation: DISTINCT removes duplicate 10; NULL is ignored. AVG of (10, 20) = 15.
Q-24
How many groups are formed by the query?
Hard
SQL Grouping
Sample Data
| EmpID | Dept | Gender |
|---|---|---|
| 1 | IT | M |
| 2 | IT | F |
| 3 | IT | M |
| 4 | HR | F |
Reference Code
SELECT Dept, Gender
FROM EMP
GROUP BY Dept, Gender;
Answer: 3
Explanation: Distinct (Dept, Gender) pairs are (IT,M), (IT,F), and (HR,F) — three groups.
Q-25
Which students are counted by the aggregate function?
Hard
SQL Aggregation
Sample Data
| RollNo | Marks |
|---|---|
| 1 | 90 |
| 2 | NULL |
| 3 | 70 |
| 4 | NULL |
Reference Code
SELECT COUNT(Marks) FROM STUDENT;
Answer: Only students with non-NULL marks
Explanation: COUNT(column) ignores NULL values and counts only rows with actual marks.
Q-26
Which query correctly produces department-wise average salary greater than 35000?
Hard
SQL Error Analysis
Answer: GROUP BY Dept HAVING AVG(Salary) > 35000
Explanation: Aggregate conditions must be written using HAVING after GROUP BY.
Q-27
Which value is returned by the query?
Hard
SQL Function
Sample Data
| Num |
|---|
| -10 |
| 5 |
| 15 |
Reference Code
SELECT MIN(Num) FROM T;
Answer: -10
Explanation: MIN returns the smallest numeric value, including negative numbers.
Q-28
Which rows are eliminated before grouping occurs?
Hard
SQL Query
Sample Data
| RollNo | Class | Marks |
|---|---|---|
| 1 | XII | 80 |
| 2 | XII | 40 |
| 3 | XI | 90 |
Reference Code
SELECT Class, AVG(Marks)
FROM STUDENT
WHERE Marks > 50
GROUP BY Class;
Answer: Rows with Marks ≤ 50
Explanation: WHERE is applied before GROUP BY, so rows with Marks ≤ 50 are removed.
Q-29
How many rows will be produced by the query?
Hard
SQL Aggregation
Sample Data
| EmpID | Dept |
|---|---|
| 1 | IT |
| 2 | IT |
| 3 | IT |
| 4 | HR |
Reference Code
SELECT Dept, COUNT(*)
FROM EMP
GROUP BY Dept
HAVING COUNT(*) > 2;
Answer: 1
Explanation: Only IT has more than two employees, so only one row is returned.
Q-30
Which statement about SQL execution order is correct?
Hard
SQL General
Answer: WHERE is evaluated before GROUP BY
Explanation: WHERE filters rows before GROUP BY and HAVING are applied.
Q-31
How many records are returned by the query?
Easy
SQL Query
Sample Data
| RollNo | Name | Class |
|---|---|---|
| 1 | Anu | XI |
| 2 | Binu | XII |
| 3 | Chetan | XI |
Reference Code
SELECT * FROM STUDENT WHERE Class='XI';
Answer: 2
Explanation: There are two students whose Class is XI.
Q-32
Which value will be returned by the query?
Easy
SQL Function
Sample Data
| Marks |
|---|
| 55 |
| 65 |
| 75 |
Reference Code
SELECT MIN(Marks) FROM STUDENT;
Answer: 55
Explanation: MIN() returns the smallest value, which is 55.
Q-33
How many distinct departments are present?
Easy
SQL Function
Sample Data
| EmpID | Dept |
|---|---|
| 1 | Sales |
| 2 | HR |
| 3 | Sales |
| 4 | IT |
Reference Code
SELECT COUNT(DISTINCT Dept) FROM EMP;
Answer: 3
Explanation: Distinct department values are Sales, HR, and IT.
Q-34
Which rows are selected by the query?
Easy
SQL Query
Sample Data
| RollNo | Marks |
|---|---|
| 1 | 40 |
| 2 | 60 |
| 3 | 80 |
Reference Code
SELECT * FROM STUDENT WHERE Marks > 50;
Answer: RollNo 2 and 3
Explanation: Rows with Marks greater than 50 are selected: RollNo 2 and 3.
Q-35
How many groups are formed by the query?
Easy
SQL Grouping
Sample Data
| EmpID | Dept |
|---|---|
| 1 | HR |
| 2 | HR |
| 3 | HR |
Reference Code
SELECT Dept FROM EMP GROUP BY Dept;
Answer: 1
Explanation: There is only one distinct department value: HR.
Q-36
Which clause is used to display unique values?
Easy
SQL General
Answer: DISTINCT
Explanation: DISTINCT removes duplicate values from the result.
Q-37
Which value will be returned by the query?
Easy
SQL Function
Sample Data
| Salary |
|---|
| 25000 |
| 30000 |
| 45000 |
Reference Code
SELECT MAX(Salary) FROM EMP;
Answer: 45000
Explanation: MAX() returns the highest salary value, which is 45000.
Q-38
Which clause is used to filter rows based on a condition?
Easy
SQL Query
Answer: WHERE
Explanation: WHERE filters rows based on conditions.
Q-39
How many values are added by the aggregate function?
Easy
SQL Aggregation
Sample Data
| Num |
|---|
| 5 |
| 10 |
| 15 |
Reference Code
SELECT SUM(Num) FROM T;
Answer: 30
Explanation: SUM adds all values: 5 + 10 + 15 = 30.
Q-40
Which clause is used to arrange the output in ascending or descending order?
Easy
SQL General
Answer: ORDER BY
Explanation: ORDER BY is used to sort query results.
Q-41
Which departments will appear in the output of the query?
Medium
SQL Grouping
Sample Data
| EmpID | Dept | Salary |
|---|---|---|
| 1 | IT | 40000 |
| 2 | IT | 20000 |
| 3 | HR | 30000 |
Reference Code
SELECT Dept
FROM EMP
WHERE Salary >= 30000
GROUP BY Dept;
Answer: IT and HR
Explanation: WHERE filters rows first. IT (40000) and HR (30000) both satisfy the condition.
Q-42
How many values are considered while computing the average?
Medium
SQL Aggregation
Sample Data
| Value |
|---|
| 10 |
| NULL |
| 20 |
| 30 |
Reference Code
SELECT AVG(Value) FROM T;
Answer: 3
Explanation: AVG ignores NULL values, so only three values are considered.
Q-43
How many groups will be formed by the query?
Medium
SQL Grouping
Sample Data
| EmpID | Dept | Location |
|---|---|---|
| 1 | IT | Delhi |
| 2 | IT | Delhi |
| 3 | IT | Mumbai |
| 4 | HR | Delhi |
Reference Code
SELECT Dept, Location
FROM EMP
GROUP BY Dept, Location;
Answer: 3
Explanation: Distinct (Dept, Location) pairs are (IT, Delhi), (IT, Mumbai), and (HR, Delhi).
Q-44
Which classes satisfy the condition in the query?
Medium
SQL Aggregation
Sample Data
| RollNo | Class | Marks |
|---|---|---|
| 1 | XI | 70 |
| 2 | XI | 80 |
| 3 | XII | 60 |
| 4 | XII | 65 |
Reference Code
SELECT Class
FROM STUDENT
GROUP BY Class
HAVING AVG(Marks) >= 70;
Answer: XI only
Explanation: Average of XI is 75, while average of XII is 62.5. Only XI satisfies the condition.
Q-45
Which rows are removed before grouping is applied?
Medium
SQL Query
Sample Data
| RollNo | Class | Marks |
|---|---|---|
| 1 | XI | 45 |
| 2 | XI | 65 |
| 3 | XII | 75 |
| 4 | XII | 55 |
Reference Code
SELECT Class, COUNT(*)
FROM STUDENT
WHERE Marks > 50
GROUP BY Class;
Answer: Rows with Marks ≤ 50
Explanation: WHERE clause removes rows with Marks less than or equal to 50 before grouping.
Q-46
What will be the output of the query?
Medium
SQL Function
Sample Data
| Num |
|---|
| 5 |
| 5 |
| 10 |
Reference Code
SELECT SUM(DISTINCT Num) FROM T;
Answer: 15
Explanation: DISTINCT removes duplicate 5. SUM of 5 and 10 is 15.
Q-47
Which clause should be used to filter grouped data?
Medium
SQL General
Answer: HAVING
Explanation: HAVING is used to filter grouped (aggregated) data.
Q-48
Which query will result in a syntax error?
Medium
SQL Error Analysis
Answer: SELECT Dept, Salary FROM EMP GROUP BY Dept
Explanation: Salary is neither aggregated nor included in GROUP BY.
Q-49
Which value is returned by the query?
Medium
SQL Function
Sample Data
| Num |
|---|
| -5 |
| 0 |
| 10 |
Reference Code
SELECT MAX(Num) FROM T;
Answer: 10
Explanation: MAX returns the highest numeric value, which is 10.
Q-50
Which clause is evaluated immediately after GROUP BY?
Medium
SQL General
Answer: HAVING
Explanation: HAVING is evaluated after GROUP BY and before ORDER BY.