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;
A
2
B
3
C
4
D
1
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;
A
Amit and Ravi
B
Neha only
C
All students
D
Ravi only
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;
A
1
B
2
C
3
D
0
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;
A
60
B
70
C
80
D
210
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';
A
1
B
2
C
3
D
0
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
A
0
B
Duplicate values
C
NULL
D
Negative numbers
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;
A
1
B
2
C
3
D
4
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
A
GROUP BY
B
WHERE
C
ORDER BY
D
HAVING
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;
A
30
B
60
C
10
D
20
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
A
SELECT
B
GROUP BY
C
WHERE
D
ORDER BY
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;
A
XI only
B
XII only
C
XI and XII
D
No 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;
A
4
B
3
C
2
D
1
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;
A
2
B
3
C
4
D
5
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;
A
IT only
B
HR only
C
Both IT and HR
D
None
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;
A
Marks < 60
B
Marks ≥ 60
C
Only XI rows
D
Only XII rows
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;
A
20
B
15
C
NULL
D
25
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
A
WHERE COUNT(*) > 1
B
GROUP BY Dept WHERE COUNT(*) > 1
C
GROUP BY Dept HAVING COUNT(*) > 1
D
HAVING Dept COUNT(*) > 1
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;
A
4
B
3
C
2
D
1
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
A
WHERE
B
HAVING
C
SELECT
D
FROM
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
A
SELECT Class, COUNT(*) FROM STUDENT GROUP BY Class
B
SELECT Class FROM STUDENT
C
SELECT Class, Marks FROM STUDENT GROUP BY Class
D
SELECT DISTINCT Class FROM STUDENT
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;
A
IT only
B
HR only
C
IT and HR
D
No department
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;
A
0
B
1
C
2
D
3
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;
A
13.33
B
15
C
20
D
10
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;
A
2
B
3
C
4
D
5
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;
A
All students
B
Only students with NULL marks
C
Only students with non-NULL marks
D
No students
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
A
WHERE AVG(Salary) > 35000
B
GROUP BY Dept WHERE AVG(Salary) > 35000
C
GROUP BY Dept HAVING AVG(Salary) > 35000
D
HAVING Dept AVG(Salary) > 35000
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;
A
-10
B
5
C
15
D
0
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;
A
Rows with Marks ≤ 50
B
Rows with Marks > 50
C
All rows of Class XII
D
Rows of Class XI
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;
A
0
B
1
C
2
D
3
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
A
HAVING is evaluated before WHERE
B
GROUP BY is evaluated before WHERE
C
WHERE is evaluated before GROUP BY
D
ORDER BY is evaluated before SELECT
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';
A
1
B
2
C
3
D
0
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;
A
55
B
65
C
75
D
195
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;
A
2
B
3
C
4
D
1
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;
A
RollNo 1 only
B
RollNo 2 and 3
C
All rows
D
RollNo 3 only
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;
A
1
B
2
C
3
D
0
Answer: 1
Explanation: There is only one distinct department value: HR.
Q-36
Which clause is used to display unique values?
Easy
SQL General
A
GROUP BY
B
DISTINCT
C
ORDER BY
D
HAVING
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;
A
25000
B
30000
C
45000
D
100000
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
A
GROUP BY
B
ORDER BY
C
WHERE
D
HAVING
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;
A
15
B
20
C
30
D
3
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
A
WHERE
B
GROUP BY
C
HAVING
D
ORDER BY
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;
A
IT only
B
HR only
C
IT and HR
D
No department
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;
A
4
B
3
C
2
D
1
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;
A
2
B
3
C
4
D
5
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;
A
XI only
B
XII only
C
XI and XII
D
No class
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;
A
Rows with Marks ≤ 50
B
Rows with Marks > 50
C
Rows of Class XI
D
Rows of Class XII
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;
A
20
B
15
C
10
D
5
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
A
WHERE
B
GROUP BY
C
HAVING
D
ORDER BY
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
A
SELECT Dept, COUNT(*) FROM EMP GROUP BY Dept
B
SELECT Dept FROM EMP
C
SELECT Dept, Salary FROM EMP GROUP BY Dept
D
SELECT DISTINCT Dept FROM EMP
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;
A
-5
B
0
C
10
D
5
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
A
WHERE
B
HAVING
C
ORDER BY
D
SELECT
Answer: HAVING
Explanation: HAVING is evaluated after GROUP BY and before ORDER BY.
◀
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
▶