Board Q&A · Class 12 Informatics Practices

Querying Using SQL: Class 12 CBSE Previous-Year Questions with Answers

CBSE Question Papers →

21 questions from CBSE board, sample and compartment papers (2024–2027), 1 to 5 marks, each with a model answer. Questions on aggregate functions (SUM, AVG, MIN, MAX, COUNT), GROUP BY and HAVING, ORDER BY, and queries on one or two tables.

Showing 21 of 292 questions
Group

Querying Using SQL

21 Questions
Querying Using SQL· 1 Mark· Q5· 2024 Board Paper
Which of the following is not an aggregate function in MYSQL?
  1. (A)(i) AVG()
  2. (B)(ii) MAX()
  3. (C)(iii) LCASE()
  4. (D)(iv) MIN()
Querying Using SQL· 1 Mark· Q4· 2025 Board Paper
Which of the following is not an aggregate function in SQL?
  1. (A)COUNT(*)
  2. (B)MIN()
  3. (C)LEFT()
  4. (D)AVG()
Querying Using SQL· 3 Marks· Q32· 2025 Board Paper
(a) Given the following tables: Table: STUDENTS S_ID | NAME | AGE | CITY 1 | Rahul | 20 | Delhi 2 | Priya | 22 | Mumbai 3 | David | 21 | Delhi 4 | Neha | 23 | Bengaluru 5 | Khurshid | 22 | Delhi Table: GRADES S_ID | SUBJECT | GRADE 1 | Math | A 2 | English | B 3 | Math | C 4 | English | A 5 | Math | B Write SQL queries for the following: (i) To display the number of students from each city. (ii) To find the average age of all students. (iii) To list the names of students and their grades. OR (b) Consider the following tables: Table 1: PRODUCTS This table stores the basic details of the products available in a shop. PID | PName | Category 201 | Laptop | Electronics 202 | Chair | Furniture 203 | Desk | Furniture 204 | Smartphone | NULL 205 | Tablet | Electronics Table 2: SALES This table records the number of units sold for each product. SaleID | PID | UnitsSold 301 | 201 | 50 302 | 202 | 100 303 | 203 | 60 304 | 204 | 80 305 | 205 | 70 Write SQL queries for the following: (i) To delete those records from table SALES whose UnitsSold is less than 80. (ii) To display names of all products whose category is not known. (iii) To display the product names along with their corresponding units sold.
Querying Using SQL· 4 Marks· Q34· 2025 Board Paper
(a) An educational institution is maintaining a database for storing the details of courses being offered. The database includes a table COURSE with the following attributes: C_ID: Stores the unique ID for each course. C_NAME: Stores the course's name. INSTRUCTOR: Stores the name of the course instructor. DURATION: Stores the duration of the course in hours. Table: COURSE C_ID | C_NAME | INSTRUCTOR | DURATION C101 | Data Structures | Dr. Alok | 40 C102 | Machine Learning | Prof. Sunita | 60 C103 | Web Development | Ms. Sakshi | 45 C104 | Database Management | Mr. Suresh | 50 C105 | Python Programming | Dr. Pawan | 35 Write SQL queries for the following: (i) To add a new record with following specifications: C_ID: C106, C_NAME: Introduction to AI, INSTRUCTOR: Ms. Preeti, DURATION: 55 (ii) To display the longest duration among all courses. (iii) To count total number of courses run by the institution. (iv) To display the instructors' name in lower case. OR (b) Ashutosh, who is a manager, has created a database to manage employee records. The database includes a table named EMPLOYEE whose attribute names are mentioned below: EID: Stores the unique ID for each employee. EMP_NAME: Stores the name of the employee. DEPT: Stores the department of the employee. SALARY: Stores the salary of the employee. JOIN_DATE: Stores the employee's joining date. Table: EMPLOYEE EID | EMP_NAME | DEPT | SALARY | JOIN_DATE E01 | ARJUN SINGH | SALES | 75000 | 2019-11-01 E02 | PRIYA JAIN | ENGINEERING | 85000 | 2020-05-20 E03 | RAVI SHARMA | MARKETING | 60000 | 2018-08-14 E04 | AYESHA | NULL | 50000 | 2021-01-10 E05 | RAHUL VERMA | FINANCE | 40000 | 2017-06-25 Write the output of the following SQL Queries: (i) Select SUBSTRING(EMP_NAME, 1, 5) from EMPLOYEE where DEPT = 'ENGINEERING'; (ii) Select EMP_NAME from EMPLOYEE where month(JOIN_DATE) = 8; (iii) Select EMP_NAME from EMPLOYEE where SALARY > 60000; (iv) Select count(DEPT) from EMPLOYEE;
Querying Using SQL· 1 Mark· Q6· 2026 Board Paper
State whether the following statement is True or False: In SQL, an aggregate function returns multiple values for each column on which it is applied.
Querying Using SQL· 1 Mark· Q21· 2026 Board Paper
Assertion (A): The output of the SQL query SELECT COUNT(name) FROM students; will differ from the output of SELECT COUNT(*) FROM students; if there are some NULL values in the name column. Reason (R): COUNT(column name) returns the count of NON NULL values in that column, whereas COUNT(*) returns the number of records in the table.
Querying Using SQL· 1 Mark· Q11· 2025 Compartment Paper
What does the following SQL query do? SELECT name, COUNT(*) FROM students GROUP BY name HAVING COUNT(*) > 1;
  1. (A)Selects students with unique name.
  2. (B)Selects students who have the same name and counts them.
  3. (C)Displays the names and the number of occurrences for those names that appear more than once in the table.
  4. (D)Orders students by name and counts them.
Querying Using SQL· 2 Marks· Q26· 2025 Compartment Paper
What are aggregate functions in SQL? Name any two aggregate functions.
Querying Using SQL· 3 Marks· Q32· 2025 Compartment Paper
(a) Given the following tables: Table: EMPLOYEES EMP_ID | EMP_NAME | DEPARTMENT | JOIN_DATE Table: PROJECTS Project_ID | EMP_ID | PROJECT_NAME | HOURS Write SQL queries to: (i) For each department, show the department names and the total count of employees working there. (ii) Display the total hours worked on the project named 'Budgeting'. (iii) Display employee names along with the names of the projects they are working on. OR (b) Given the following tables: Table: STUDENTS StudentID | StudentName | Class Table: EXAMS ExamID | StudentID | Subject | Marks Write SQL queries to: (i) Calculate the average marks obtained by students in Mathematics. (ii) For each class, show the class and the total count of students studying there. (iii) Display the student names and their corresponding subjects.
Querying Using SQL· 1 Mark· Q8· 2024 Sample Paper
Raj, a Database Administrator, needs to display the average pay of workers from those departments which have more than five employees. He is experiencing a problem while running the following query: SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5 GROUP BY DEPT; Which of the following is a correct query to perform the given task?
  1. (A)i. SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5 GROUP BY DEPT;
  2. (B)ii. SELECT DEPT, AVG(SAL) FROM EMP HAVING COUNT(*) > 5 GROUP BY DEPT;
  3. (C)iii. SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT WHERE COUNT(*) > 5;
  4. (D)iv. SELECT DEPT, AVG(SAL) FROM EMP GROUP BY DEPT HAVING COUNT(*) > 5;
Querying Using SQL· 2 Marks· Q25· 2024 Sample Paper
What are aggregate functions in SQL? Name any two.
Querying Using SQL· 3 Marks· Q26· 2024 Sample Paper
Based on the SQL table CAR_SALES, write suitable queries for the following: +--------+-------------------+--------+-------+-------+ | NUMBER | SEGMENT | FUEL | QT1 | QT2 | +--------+-------------------+--------+-------+-------+ | 1 | Compact HatchBack | Petrol | 56000 | 70000 | | 2 | Compact HatchBack | Diesel | 34000 | 40000 | | 3 | MUV | Petrol | 33000 | 35000 | | 4 | MUV | Diesel | 14000 | 15000 | | 5 | SUV | Petrol | 27000 | 54000 | | 6 | SUV | Diesel | 18000 | 30000 | | 7 | Sedan | Petrol | 8000 | 10000 | | 8 | Sedan | Diesel | 1000 | 5000 | +--------+-------------------+--------+-------+-------+ i. Display fuel wise average sales in the first quarter. ii. Display segment wise highest sales in the second quarter. iii. Display the records in the descending order of sales in the second quarter. OR Predict the output of the following queries based on the table CAR_SALES given above: i. SELECT LEFT(SEGMENT,2) FROM CAR_SALES WHERE FUEL= "PETROL"; ii. SELECT (QT2-QT1)/2 "AVG SALE" FROM CAR_SALES WHERE SEGMENT= "SUV"; iii. SELECT SUM(QT1) "TOT SALE" FROM CAR_SALES WHERE FUEL= "DIESEL";
Querying Using SQL· 1 Mark· Q8· 2025 Sample Paper
State whether the following statement is True or False: In SQL, the HAVING clause is used to apply filter on groups formed by the GROUP BY clause.
Querying Using SQL· 1 Mark· Q11· 2025 Sample Paper
Fill in the Blank The COUNT(*) function provides the total number of __________ within a relation (table) in a relational database.
  1. (A)Columns
  2. (B)Unique values
  3. (C)Not-null values
  4. (D)Rows
Querying Using SQL· 3 Marks· Q32· 2025 Sample Paper
(A) Consider the following tables: Table 1: EMPLOYEE, which stores Employee ID (EMP_ID), Employee Name (EMP_NAME), Employee City (EMP_CITY) Table 2: PAYROLL, which stores Employee ID (EMP_ID), Department (DEPARTMENT), Designation (DESIGNATION), and Salary (SALARY) for various employees. Note: Attribute names are written within brackets. Table: EMPLOYEE EMP_ID | EMP_NAME | EMP_CITY 1 | ABHINAV | AGRA 2 | KABIR | FARIDABAD 3 | ESHA | NOIDA 4 | PAUL | SEOUL 5 | VICTORIA | LONDON Table: PAYROLL EMP_ID | DEPARTMENT | DESIGNATION | SALARY 1 | SALES | MANAGER | 75000 2 | SALES | ASSOCIATE | 50000 3 | ENGINEERING | MANAGER | 95000 4 | ENGINEERING | ENGINEER | 70000 5 | MARKETING | MANAGER | 65000 Write appropriate SQL queries for the following: I. Display department-wise average Salary. II. List all designations in the decreasing order of Salary. III. Display employee name along with their corresponding departments. OR (B) Consider the following tables: Table 1: ATHLETE, which stores AthleteID, Name, Country. The table displays basic information of the athletes. Table 2: MEDALS, which stores AthleteID, Sport, and Medals. The table displays the number of medals won by each athlete in their respective sports. Table: ATHLETE AthleteID | Name | COUNTRY 101 | Arjun | INDIA 102 | Priya | INDIA 103 | Asif | UAE 104 | Rozy | USA 105 | David | DENMARK Table: MEDALS AthleteID | Sport | Medals 101 | Swimming | 8 102 | Track | 3 103 | Gymnastics | 5 104 | Swimming | 2 105 | Track | 6 Write appropriate SQL queries for the following: I. Display the sports-wise total number of medals won. II. Display the names of all the Indian athletes in uppercase. III. Display the athlete name along with their corresponding sports.
Querying Using SQL· 5 Marks· Q37· 2025 Sample Paper
(A) Write suitable SQL query for the following: I. To display the average score from the test_results column (attribute) in the Exams table. II. To display the last three characters of the registration_number column (attribute) in the Vehicles table. (Note: The registration numbers are stored in the format DL-01-AV-1234) III. To display the data from the column (attribute) username in the Users table, after eliminating any leading and trailing spaces. IV. To display the maximum value in the salary column (attribute) of the Employees table. V. To determine the count of rows in the Suppliers table. OR (B) Write suitable SQL query for the following: I. Round the value of pi (3.14159) to two decimal places. II. Calculate the remainder when 125 is divided by 8. III. Display the number of characters in the word 'NewDelhi'. IV. Display the first 5 characters from the word 'Informatics Practices'. V. Display details from 'email' column (attribute), in the 'Students' table, after removing any leading and trailing spaces.
Querying Using SQL· 1 Mark· Q11· 2026 Sample Paper
Which of the following SQL function is used to count the non-NULL values in a column named column_name?
  1. (A)COUNT(*)
  2. (B)COUNT(column_name)
  3. (C)SUM(column_name)
  4. (D)AVG(column_name)
Querying Using SQL· 1 Mark· Q14· 2026 Sample Paper
Which SQL command is used to sort rows in either ascending or descending order of values in a specific column?
  1. (A)ORDER BY
  2. (B)SORT BY
  3. (C)GROUP BY
  4. (D)SORT ON
Querying Using SQL· 1 Mark· Q19· 2026 Sample Paper
Which of the following is NOT an aggregate function in SQL?
  1. (A)MIN()
  2. (B)SUM()
  3. (C)UPPER()
  4. (D)AVG()
Querying Using SQL· 1 Mark· Q9· 2027 Sample Paper
Fill in the blank: The SQL clause used to filter the groups formed by the GROUP BY clause based on a specific condition is ____________.
Querying Using SQL· 1 Mark· Q11· 2027 Sample Paper
Which keyword is used with the ORDER BY clause to sort data in descending order?
  1. (A)DESC
  2. (B)DOWN
  3. (C)DSC
  4. (D)REVERSE