43 questions from CBSE board, sample and compartment papers (2024–2027), 1 to 5 marks, each with a model answer. Questions on math functions (POWER, MOD, ROUND), text functions (UCASE, LCASE, MID, SUBSTR, LEFT, RIGHT, INSTR, LENGTH, TRIM), date functions (NOW, DATE, MONTH, MONTHNAME, YEAR, DAYNAME) and aggregate functions: predicting outputs and writing queries.
(a) Consider the given table and write the following queries in MySQL:
Table : Sports
Sid | SName | Fees | DateofPlay | CoachID
1 | Karate | 1200 | 2024-08-24 | S1
2 | Football | 1800 | 2024-09-13 | S2
3 | Cricket | 1500 | 2024-06-14 | S3
4 | Lawn Tennis | 2500 | 2024-09-25 | S4
5 | Badminton | 1800 | 2024-10-20 | S5
(i) To display Sid and name of those sports which are to be played in the month of September.
(ii) To display all Sports names in lower case.
(iii) To display last two characters of all sports names whose fees is less than 1500.
OR
(b) Predict the output of the following queries based on the table Sports given above:
(i) SELECT UCASE(TRIM(SName)) FROM Sports WHERE Sid = 5;
(ii) SELECT LEFT(SName, 3) FROM Sports WHERE DateofPlay > '2024-09-13';
(iii) SELECT SUBSTR(CoachId, 1) FROM Sports WHERE SName = 'Cricket' OR Fees >= 2000;
Model answer
(a)
(i) SELECT Sid, SName FROM Sports WHERE MONTH(DateofPlay) = 9;
(ii) SELECT LOWER(SName) FROM Sports;
(iii) SELECT RIGHT(SName, 2) FROM Sports WHERE Fees < 1500;
OR
(b)
(i) BADMINTON
(ii)
Law
Bad
(iii)
S3
S4
-- (a) Queries
SELECT Sid, SName FROM Sports WHERE MONTH(DateofPlay) = 9;
SELECT LOWER(SName) FROM Sports;
SELECT RIGHT(SName, 2) FROM Sports WHERE Fees < 1500;
With respect to SQL, match the function given in column-II with categories given in column-I:
I | II
(i) Math function | (a) COUNT()
(ii) Aggregate function | (b) ROUND()
(iii) Date function | (c) RIGHT()
(iv) Text function | (d) YEAR()
Assertion (A): The ROUND() function in SQL can be used to round off a number to a specified number of decimal places.
Reason (R): The ROUND() function is a string function that accepts character values as input and returns numerical values as output.
(A)Both Assertion (A) and Reason (R) are True and Reason (R) is the correct explanation for Assertion (A).
(B)Both Assertion (A) and Reason (R) are True and Reason (R) is not the correct explanation for Assertion (A).
(C)Assertion (A) is True and Reason (R) is False.
(D)Assertion (A) is False, but Reason (R) is True.
Model answer
Assertion (A) is True and Reason (R) is False
Explanation: ROUND() is a Mathematical function, not a string function.
Consider the string, "Informatics Practices". Write suitable SQL queries for the following:
(i) To convert the entire string to uppercase.
(ii) To display the total number of characters in the given string.
(a) Write SQL query for the following:
(i) To display sum total of all the values of the Score column, from STUDENTS table.
(ii) To display the first five characters of the Name column from STUDENTS table.
(iii) To display the values of Name column from the STUDENTS table, after removing the trailing spaces.
(iv) To retrieve the lowest score from the Score column of GRADES table.
(v) To increase the fee of all students by 100, in the STUDENTS table. (The name of the column is FEE)
OR
(b) Write SQL queries for the following:
(i) To calculate the square of 15.
(ii) To round the number 456.789 to the nearest integer.
(iii) To display the position of first occurrence of 'com' in the string 'mycommercial.com'.
(iv) To display the name of the day for the date '2024-11-07'.
(v) To display the current date and time.
State whether the following statement is True or False:
The INSTR (string1, string2) function in SQL returns 0 if string2 is not present as a substring in string1.
Model answer
True
Explanation: INSTR() returns the position of the first occurrence of a substring. If it's not found, it returns 0.
Write SQL queries to perform the following:
(I) Display the month (in numeric form) of the date '2026-01-01'.
(II) Display only the year part from the date '2026-01-01'.
/* (I) Month */
SELECT MONTH('2026-01-01');
/* (II) Year */
SELECT YEAR('2026-01-01');
(a) Write a suitable SQL query based on the Guest table:
(I) Display last 3 characters of guest name in upper case.
(II) Display the name of the guest along with the day name of check-in date.
(III) Display the remainder when charges are divided by 1000.
(IV) Extract and display three characters, starting from the second character, of each guest name.
OR
(b) Write the output of the following SQL Queries based on the ORDERS table:
I. SELECT CUSTOMERNAME FROM ORDERS WHERE DISCOUNT IS NOT NULL;
II. SELECT CUSTOMERNAME, DISCOUNT FROM ORDERS WHERE DISCOUNT BETWEEN 5 AND 10;
III. SELECT MONTHNAME (ORDERDATE) FROM ORDERS WHERE ORDERDATE IS NOT NULL;
IV. SELECT ORDERID, DAY (ORDERDATE) FROM ORDERS;
Model answer
--- Solution (a) ---
I. SELECT UPPER(RIGHT(GuestName, 3)) FROM Guest;
II. SELECT GuestName, DAYNAME(CheckInDate) FROM Guest;
III. SELECT MOD(Charges, 1000) FROM Guest;
IV. SELECT SUBSTR(GuestName, 2, 3) FROM Guest;
--- Solution (b) Outputs ---
I.
Hemant
Neha
Keshav
II.
Hemant 10
Keshav 5
III.
March
January
December
IV.
101 1
102 NULL
103 20
104 25
(a) Write suitable SQL query for the following:
I. Display only the date part from the date/time expression '2026-01-01 10:10:10'.
II. Convert all customer names from Cust_Name column to lowercase in Customer table.
III. Extract the first 4 characters from the City_Name column in Location table.
IV. Display the name of the city from CITY column in EVENT table, after removing leading spaces.
V. Find the average salary from Salary column in Employees table.
OR
(b) Write suitable SQL query for the following:
I. To display the value of 17 squared.
II. To display the day part of the dates in Hire_Date column.
III. To display the maximum value of the Bill_Amount column.
IV. To remove leading and trailing spaces from Location column.
V. To display total salary from tot_sal column.
Model answer
--- Solution (a) ---
I. SELECT DATE('2026-01-01 10:10:10');
II. SELECT LOWER(Cust_Name) FROM Customer;
III. SELECT LEFT(City_Name, 4) FROM Location;
IV. SELECT LTRIM(CITY) FROM EVENT;
V. SELECT AVG(Salary) FROM Employees;
--- Solution (b) ---
I. SELECT POW(17, 2);
II. SELECT DAY(Hire_Date) FROM Employee;
III. SELECT MAX(Bill_Amount) FROM Bill;
IV. UPDATE Branch SET Location = TRIM(Location); /* Or SELECT TRIM(Location) FROM Branch; */
V. SELECT SUM(tot_sal) FROM Employees;
MySQL Functions· 1 Mark· Q2· 2025 Compartment Paper
What will be the output of the following SQL command?
SELECT MOD (20,6);
(A)-2
(B)4
(C)2
(D)8
Model answer
2
Explanation: MOD(20, 6) returns the remainder when 20 is divided by 6. 20 = 6 * 3 + 2, so the remainder is 2.
MySQL Functions· 1 Mark· Q8· 2025 Compartment Paper
What will be the output of the following SQL query?
SELECT MID ('INCREDIBLE INDIA', 6,3);
(A)EDI
(B)RED
(C)DIB
(D)CREDIB
Model answer
DIB
Explanation: MID(string, start, length). Starting from the 6th character 'D', it takes 3 characters: 'D', 'I', 'B'.
MySQL Functions· 2 Marks· Q24· 2025 Compartment Paper
Write SQL Queries to perform the following task:
(i) Extract the leftmost 5 characters after removing the leading and trailing spaces from "DESIGN THINKING"
(ii) Display the day name of the week when the National Space Day was celebrated first i.e., '23-08-2023'.
MySQL Functions· 5 Marks· Q37· 2025 Compartment Paper
(a) Write suitable SQL query for the following:
(i) Display the minimum value in the Salary column from the EMPLOYEES table.
(ii) Display the FirstName column values in lowercase from the EMPLOYEES table.
(iii) Retrieve the DepartmentName column values in uppercase from the DEPARTMENTS table, where the DepartmentName has a length of 7 characters.
(iv) Show the remainder when dividing each value in the Salary column by 1000 in the EMPLOYEES table.
(v) Count the rows in the EMPLOYEES table where Salary is greater than 50000.
(b) Write suitable SQL queries for the following:
(i) Find the power of 5 raised to 3.
(ii) Convert the string 'DATA ANALYSIS' to lowercase.
(iii) Display the first 4 characters of the string 'Information'.
(iv) Extract the year from the date '1995-11-15'.
(v) Display the number of characters in the string 'Cyber Security'.
Model answer
(a) SQL Queries:
(i) SELECT MIN(Salary) FROM EMPLOYEES;
(ii) SELECT LOWER(FirstName) FROM EMPLOYEES;
(iii) SELECT UPPER(DepartmentName) FROM DEPARTMENTS WHERE LENGTH(DepartmentName) = 7;
(iv) SELECT MOD(Salary, 1000) FROM EMPLOYEES;
(v) SELECT COUNT(*) FROM EMPLOYEES WHERE Salary > 50000;
(b) SQL Queries:
(i) SELECT POW(5, 3);
(ii) SELECT LOWER('DATA ANALYSIS');
(iii) SELECT LEFT('Information', 4);
(iv) SELECT YEAR('1995-11-15');
(v) SELECT LENGTH('Cyber Security');
/* Part A Queries */
SELECT MIN(Salary) FROM EMPLOYEES;
SELECT LOWER(FirstName) FROM EMPLOYEES;
SELECT UPPER(DepartmentName) FROM DEPARTMENTS WHERE LENGTH(DepartmentName) = 7;
SELECT MOD(Salary, 1000) FROM EMPLOYEES;
SELECT COUNT(*) FROM EMPLOYEES WHERE Salary > 50000;
/* Part B Queries */
SELECT POW(5, 3);
SELECT LOWER('DATA ANALYSIS');
SELECT LEFT('Information', 4);
SELECT YEAR('1995-11-15');
SELECT LENGTH('Cyber Security');
Which of the following SQL functions does not belong to the Math functions category?
i. POWER()
ii. ROUND()
iii. LENGTH()
iv. MOD()
(A)i. POWER()
(B)ii. ROUND()
(C)iii. LENGTH()
(D)iv. MOD()
Model answer
iii. LENGTH ()
Explanation: LENGTH() is a text/string function that returns the character/byte count of a string, whereas POWER(), ROUND(), and MOD() are math functions.
Consider the given SQL string:
“12#All the Best!”
Write suitable SQL queries for the following:
i. Returns the position of the first occurrence of the substring “the” in the given string.
ii. To extract last five characters from the string.
Model answer
i. SELECT INSTR("12#All the Best!","the");
ii. SELECT RIGHT("12#All the Best!",5);
SELECT INSTR("12#All the Best!","the");
SELECT RIGHT("12#All the Best!",5);
Preeti manages database in a blockchain start-up. For business purposes, she created a table named BLOCKCHAIN. Assist her by writing the following queries:
TABLE: BLOCKCHAIN
+----+----------+-------+--------+------------------+
| id | user | value | hash | transaction_date |
+----+----------+-------+--------+------------------+
| 1 | Steve | 900 | ERTYU | 2020-09-19 |
| 2 | Meesha | 145 | @345r | 2021-03-23 |
| 3 | Nimisha | 567 | #wert5 | 2020-05-06 |
| 4 | Pihu | 678 | %rtyu | 2022-07-13 |
| 5 | Kopal | 768 | rrt4% | 2021-05-15 |
| 7 | Palakshi | 534 | wer@3 | 2022-11-29 |
+----+----------+-------+--------+------------------+
i. Write a query to display the year of oldest transaction.
ii. Write a query to display the month of most recent transaction.
iii. Write a query to display all the transactions done in the month of May.
iv. Write a query to count total number of transactions in the year 2022.
Model answer
i. SELECT YEAR(MIN(TRANSACTION_DATE)) FROM BLOCKCHAIN;
ii. SELECT MONTH(MAX(TRANSACTION_DATE)) FROM BLOCKCHAIN;
iii. SELECT * FROM BLOCKCHAIN WHERE MONTHNAME(TRANSACTION_DATE)='MAY';
iv. SELECT COUNT(ID) FROM BLOCKCHAIN WHERE YEAR(TRANSACTION_DATE)=2022;
SELECT YEAR(MIN(TRANSACTION_DATE)) FROM BLOCKCHAIN;
SELECT MONTH(MAX(TRANSACTION_DATE)) FROM BLOCKCHAIN;
SELECT * FROM BLOCKCHAIN WHERE MONTHNAME(TRANSACTION_DATE)='MAY';
SELECT COUNT(ID) FROM BLOCKCHAIN WHERE YEAR(TRANSACTION_DATE)=2022;
Write suitable SQL queries for the following:
i. To calculate the exponent for 3 raised to the power of 4.
ii. To display current date and time.
iii. To round off the value -34.4567 to 2 decimal place.
iv. To remove all the probable leading and trailing spaces from the column userid of the table named user.
v. To display the length of the string ‘FIFA World Cup’.
OR
Kabir has created following table named exam:
+-------+---------+------------------+-------+
| RegNo | Name | Subject | Marks |
+-------+---------+------------------+-------+
| 1 | Sanya | Computer Science | 98 |
| 2 | Sanchay | IP | 100 |
| 3 | Vinesh | CS | 90 |
| 4 | Sneha | IP | 99 |
| 5 | Akshita | IP | 100 |
+-------+---------+------------------+-------+
Help him in writing SQL queries to the perform the following task:
i. Insert a new record in the table having following values:
[6,'Khushi','CS',85]
ii. To change the value “IP” to “Informatics Practices” in subject column.
iii. To remove the records of those students whose marks are less than 30 .
iv. To add a new column Grade of suitable datatype.
v. To display records of “Informatics Practices” subject.
Model answer
i. SELECT POWER(3,4);
ii. SELECT NOW();
iii. SELECT ROUND(-34.4567,2);
iv. SELECT TRIM(USERID) FROM USER;
v. SELECT LENGTH("FIFA World Cup");
OR
i. INSERT INTO EXAM VALUES(6,'Khushi','CS',85);
ii. UPDATE EXAM SET subject= "Informatics Practices" where subject = "IP";
iii. DELETE FROM EXAM WHERE marks<30;
iv. ALTER TABLE EXAM ADD COLUMN grade varchar(2);
v. Select * from exam where subject="Informatics Practices";
SELECT POWER(3,4);
SELECT NOW();
SELECT ROUND(-34.4567,2);
SELECT TRIM(USERID) FROM USER;
SELECT LENGTH("FIFA World Cup");
Match the following SQL functions/clauses with their descriptions:
SQL Function | Description
P. | MAX() | 1. Find the position of a substring in a string.
Q. | SUBSTRING() | 2. Returns the maximum value in a column.
R. | INSTR() | 3. Sorts the data based on a column.
S. | ORDER BY | 4. Extracts a portion of a string.
(A)P-2, Q-4, R-3, S-1
(B)P-2, Q-4, R-1, S-3
(C)P-4, Q-3, R-2, S-1
(D)P-4, Q-2, R-1, S-3
Model answer
(B) P-2, Q-4, R-1, S-3
Explanation: MAX is aggregate, SUBSTRING extracts text, INSTR finds index, ORDER BY sorts.
Consider the string: "Database Management System". Write suitable SQL queries for the following:
I. To extract and display "Manage" from the string.
II. Display the position of the first occurrence of "base" in the given string.
(A) Rahul, who works as a database designer, has developed a database for a bookshop. This database includes a table BOOK whose column (attribute) names are mentioned below:
BCODE: Shows the unique code for each book.
TITLE: Indicates the book's title.
AUTHOR: Specifies the author's name.
PRICE: Lists the cost of the book.
Table: BOOK
BCODE | TITLE | AUTHOR | PRICE
B001 | MIDNIGHT'S CHILDREN | SALMAN RUSHDIE | 500
B002 | THE GOD OF SMALL THINGS | ARUNDHATI ROY | 450
B003 | A SUITABLE BOY | VIKRAM SETH | 600
B004 | THE WHITE TIGER | ARAVIND ADIGA | 399
B005 | TRAIN TO PAKISTAN | KHUSHWANT SINGH | 350
I. Write SQL query to display book titles in lowercase.
II. Write SQL query to display the highest price among the books.
III. Write SQL query to display the number of characters in each book title.
IV. Write SQL query to display the Book Code and Price sorted by Price in descending order.
OR
(B) Dr. Kavita has created a database for a hospital's pharmacy. The database includes a table named MEDICINE whose column (attribute) names are mentioned below:
MID: Shows the unique code for each medicine.
MED_NAME: Specifies the medicine name.
SUPP_CITY: Specifies the city where the supplier is located.
STOCK: Indicates the quantity of medicine available.
DEL_DATE: Specifies the date when the medicine was delivered.
Table: MEDICINE
MID | MED_NAME | SUPP_CITY | STOCK | DEL_DATE
M01 | PARACETAMOL | MUMBAI | 200 | 2023-06-15
M02 | AMOXICILLIN | KOLKATA | 50 | 2023-03-21
M03 | COUGH SYRUP | BENGALURU | 120 | 2023-02-10
M04 | INSULIN | CHENNAI | 135 | 2023-01-25
M05 | IBUPROFEN | AHMEDABAD | 30 | 2023-04-05
Write the output of the following SQL Queries.
I. Select LENGTH(MED_NAME) from MEDICINE where STOCK > 100;
II. Select MED_NAME from MEDICINE where month(DEL_DATE) = 4;
III. Select MED_NAME from MEDICINE where STOCK between 120 and 200;
IV. Select max(DEL_DATE) from MEDICINE;
/* Part A (Books) */
SELECT LOWER(TITLE) FROM BOOK;
SELECT MAX(PRICE) FROM BOOK;
SELECT LENGTH(TITLE) FROM BOOK;
SELECT BCODE, PRICE FROM BOOK ORDER BY PRICE DESC;
/* Part B (Medicine) */
SELECT LENGTH(MED_NAME) FROM MEDICINE WHERE STOCK > 100;
SELECT MED_NAME FROM MEDICINE WHERE MONTH(DEL_DATE) = 4;
SELECT MED_NAME FROM MEDICINE WHERE STOCK BETWEEN 120 AND 200;
SELECT MAX(DEL_DATE) FROM MEDICINE;
Write SQL queries to perform the following:
I. Display the name of the day (e.g., Monday, Tuesday) for the date '2026-01-01'.
II. Find and display the position of the substring "India" in the string "Incredible India"
(A) Raghav, who works as a database designer, has created a table Student as shown below:
Table: Student
StudentID | Name | City | Marks | Admission_Date
101 | Aarav Sharma | Delhi | 85 | 2022-04-01
102 | Priya Iyer | Mumbai | 78 | 2021-05-15
103 | Rohan Verma | Bangalore | 92 | 2020-06-10
104 | Simran Patel | Delhi | 88 | 2022-03-20
105 | Karan Yadav | Mumbai | 75 | 2021-08-05
Write suitable SQL query for the following.
I. Show the Name and City of the students, both in uppercase, sorted alphabetically by Name.
II. Display the Student ID along with the name of the month in which the student was admitted to the school.
III. Calculate and display the average marks obtained by students.
IV. Show the names of the cities and the number of students residing in the city.
OR
(B) Consider the following table and write the output of the following SQL Queries.
Table: Student
StudentID | Name | DateofBirth | Marks | City
301 | Aryan | 15-03-2005 | 88 | Delhi
302 | Ayesha | NULL | 90 | NULL
304 | Aditi | NULL | 85 | Pune
305 | Rajesh | 11-01-2006 | 72 | NULL
306 | Maria | 29-04-2005 | 95 | Chennai
Write the output of the following SQL Queries.
I. SELECT Name, LENGTH(Name) FROM Student WHERE StudentID < 303;
II. SELECT lower(Name) FROM Student WHERE MONTH(DateofBirth)= 3;
III. SELECT AVG(Marks) FROM Student;
IV. SELECT Name, Marks FROM Student WHERE Marks BETWEEN 90 AND 100;
SELECT UPPER(Name), UPPER(City) FROM Student ORDER BY Name;
SELECT StudentID, MONTHNAME(Admission_Date) FROM Student;
SELECT AVG(Marks) FROM Student;
SELECT City, COUNT(*) FROM Student GROUP BY City;
(A) Write suitable SQL query for the following:
I. To extract the first five characters from the product_code column in the Products table.
II. To display the total number of orders from Order_Id column in the Orders table.
III. To display the year of the order dates from the order_date column in the Orders table.
IV. To display the Address column from the Customers table after removing leading and trailing spaces
V. To display the current date.
OR
(B) Write suitable SQL query for the following:
I. To display the total number of characters in the string DatabaseSystems.
II. Find the position of the first occurrence of the letter 'a' in the Product_Name column of the Products table.
III. Calculate the square of the Amount for each transaction in the Tran_Amount column of the Transactions table.
IV. To display the average salary from the Salaries column in the Employees table.
V. Display the total sum of the Salary from the Salary column in the Employees table.
SELECT LEFT(product_code, 5) FROM Products;
SELECT COUNT(Order_Id) FROM Orders;
SELECT YEAR(order_date) FROM Orders;
SELECT TRIM(Address) FROM Customers;
SELECT CURDATE();
Write SQL queries for the following requirements:
(i) Display the last 3 characters of the attribute Ename from the EMPLOYEE table.
(ii) Find the position of the substring 'ma' in the string 'Informatics'.
Model answer
(i) SELECT RIGHT(Ename, 3) FROM EMPLOYEE;
(ii) SELECT INSTR('Informatics', 'ma');
SELECT RIGHT(Ename, 3) FROM EMPLOYEE;
SELECT INSTR('Informatics', 'ma');
Consider the table HOSPITAL, which contains the following columns:
Column Name | Remark
PNo | Patient Number
PName | Patient Name
Dept | Department
DOA | Date of Admission
Table: HOSPITAL
PNo | PName | Dept | DOA
101 | Ravi Kumar | Cardiology | 2024-05-12
102 | Anita Sharma | Neurology | 2025-06-01
103 | Mohan Das | Cardiology | 2023-05-18
104 | Seema Verma | Orthopedics | 2022-04-22
105 | Rahul Singh | Cardiology | 2025-03-30
Write SQL queries to perform the following tasks:
(i) Display the names of all patients in the Cardiology department in lowercase.
(ii) Display each patient's number along with the day name of the week on which they were admitted.
(iii) Display the patient names arranged in alphabetical order.
Model answer
(i) SELECT LOWER(PName) FROM HOSPITAL WHERE Dept = 'Cardiology';
(ii) SELECT PNo, DAYNAME(DOA) FROM HOSPITAL;
(iii) SELECT PName FROM HOSPITAL ORDER BY PName ASC;
SELECT LOWER(PName) FROM HOSPITAL WHERE Dept = 'Cardiology';
SELECT PNo, DAYNAME(DOA) FROM HOSPITAL;
SELECT PName FROM HOSPITAL ORDER BY PName ASC;
(A) Consider a table named STUDENT containing the following data:
ID | Name | DOB
1 | Aman | 2005-08-15
2 | Vinod | 2006-01-26
3 | Saurabh | 2004-01-01
Write the output of the following SQL queries:
(i) SELECT UPPER(Name), LENGTH(Name) FROM STUDENT WHERE ID = 2;
(ii) SELECT DAY(DOB), YEAR(DOB) FROM STUDENT WHERE ID = 3;
(iii) SELECT RIGHT(Name, 3) FROM STUDENT WHERE ID = 1;
OR
(B) Write the output of the following SQL queries:
(i) SELECT POWER(MOD(13, 5), 2);
(ii) SELECT UCASE(MID("Digital India", 9, 5));
(iii) SELECT LENGTH(TRIM(" Informatics "));
Model answer
(A) (i)
UPPER(Name) | LENGTH(Name)
VINOD | 5
(ii)
DAY(DOB) | YEAR(DOB)
1 | 2004
(iii)
RIGHT(Name, 3)
man
OR
(B) (i) 9
(ii) INDIA
(iii) 11