Board Q&A · Class 12 Computer Science

Simple Queries in SQL: Class 12 CBSE Previous-Year Questions with Answers

CBSE Question Papers →

26 questions from CBSE board, sample and compartment papers (2024–2027), 1 to 4 marks, each with a model answer. Questions on writing SQL queries and predicting their output: WHERE conditions, BETWEEN, LIKE, IS NULL, ORDER BY, DISTINCT, aggregate functions and GROUP BY, plus some INSERT and UPDATE commands and MySQL data types.

Showing 26 of 295 questions
Group

Simple Queries in SQL

26 Questions
Simple Queries in SQL· 1 Mark· Q2· 2024 Board Paper
The SELECT statement when combined with ________ clause, returns records without repetition.
  1. (A)DISTINCT
  2. (B)DESCRIBE
  3. (C)UNIQUE
  4. (D)NULL
Simple Queries in SQL· 1 Mark· Q5· 2024 Board Paper
In SQL, the aggregate function which will display the cardinality of the table is ________.
  1. (A)sum()
  2. (B)count(*)
  3. (C)avg()
  4. (D)sum(*)
Simple Queries in SQL· 3 Marks· Q27· 2024 Board Paper
Consider the table ORDERS given below and write the output of the SQL queries that follow: Table: ORDERS [ORDNO, ITEM, QTY, RATE, ORDATE] 1001 | RICE | 23 | 120 | 2023-09-10 1002 | PULSES | 13 | 120 | 2023-10-18 1003 | RICE | 25 | 110 | 2023-11-17 1004 | WHEAT | 28 | 65 | 2023-12-25 1005 | PULSES | 16 | 110 | 2024-01-15 1006 | WHEAT | 27 | 55 | 2024-04-15 1007 | WHEAT | 25 | 60 | 2024-04-30 (i) SELECT ITEM, SUM(QTY) FROM ORDERS GROUP BY ITEM; (ii) SELECT ITEM, QTY FROM ORDERS WHERE ORDATE BETWEEN '2023-11-01' AND '2023-12-31'; (iii) SELECT ORDNO, ORDATE FROM ORDERS WHERE ITEM = 'WHEAT' AND RATE>=60;
Simple Queries in SQL· 4 Marks· Q31· 2024 Board Paper
Consider the tables Admin and Transport given below: Table: Admin [S_id, S_name, Address, S_type] S001 | Sandhya | Rohini | Day Boarder S002 | Vedanshi | Rohtak | Day Scholar S003 | Vibhu | Raj Nagar | NULL S004 | Atharva | Rampur | Day Boarder Table: Transport [S_id, Bus_no, Stop_name] S002 | TSS10 | Sarai Kale Khan S004 | TSS12 | Sainik Vihar S005 | TSS10 | Kamla Nagar Write SQL queries for the following: (i) Display the student name and their stop name from the tables Admin and Transport. (ii) Display the number of students whose S_type is not known. (iii) Display all details of the students whose name starts with 'V'. (iv) Display student id and address in alphabetical order of student name, from the table Admin.
Simple Queries in SQL· 1 Mark· Q14· 2025 Board Paper
Which aggregate function in SQL displays the number of values in the specified column ignoring the NULL values?
  1. (A)len()
  2. (B)count()
  3. (C)number()
  4. (D)num()
Simple Queries in SQL· 1 Mark· Q15· 2025 Board Paper
In MYSQL, which type of value should not be enclosed within quotation marks?
  1. (A)DATE
  2. (B)VARCHAR
  3. (C)FLOAT
  4. (D)CHAR
Simple Queries in SQL· 4 Marks· Q32· 2025 Board Paper
Suman has created a table named WORKER with a set of records to maintain the data of the construction sites, which consists of WID, WNAME, WAGE, HOURS, TYPE, and SITEID. After creating the table, she entered data in it, which is as follows: WID | WNAME | WAGE | HOURS | TYPE | SITEID W01 | Ahmed J | 1500 | 200 | Unskilled | 103 W11 | Naveen S | 520 | 100 | Skilled | 101 W02 | Jacob B | 780 | 95 | Unskilled | 101 W15 | Nihal K | 560 | 110 | Semiskilled | NULL W10 | Anju S | 1200 | 130 | Skilled | 103 (a) Based on the data given above, answer the following questions: (i) Write the SQL statement to display the names and wages of those workers whose wages are between 800 and 1500. (ii) Write the SQL statement to display the record of workers whose SITEID is not known. (iii) Write the SQL statement to display WNAME, WAGE and HOURS of all those workers whose TYPE is 'Skilled'. (iv) Write the SQL statement to change the WAGE to 1200 of the workers where the TYPE is "Semiskilled". OR (b) Considering the above given table WORKER, write the output on execution of the following SQL commands: (i) SELECT WNAME, WAGE*HOURS FROM WORKER WHERE SITEID = 103; (ii) SELECT COUNT (DISTINCT TYPE) FROM WORKER; (iii) SELECT MAX(WAGE), MIN(WAGE), TYPE FROM WORKER GROUP BY TYPE; (iv) SELECT WNAME,SITEID FROM WORKER WHERE TYPE="Unskilled" ORDER BY HOURS;
Simple Queries in SQL· 4 Marks· Q34· 2025 Board Paper
Assume that you are working in the IT Department of a Creative Art Gallery (CAG), which sells different forms of art creations like Paintings, Sculptures etc. The data of Art Creations and Artists are kept in tables Articles and Artists respectively. Following are few records from these two tables: Table: Articles Code | A_Code | Article | DOC | Price PL001 | A0001 | Painting | 2018-10-19 | 20000 SC028 | A0004 | Sculpture | 2021-01-15 | 16000 QL005 | A0003 | Quilling | 2024-04-24 | 3000 Table: Artists A_Code | Name | Phone | Email | DOB A0001 | Roy | 595923 | r@CrAG.com | 1986-10-12 A0002 | Ghosh | 1122334 | ghosh@CrAG.com | 1972-02-05 A0003 | Gargi | 121212 | Gargi@CrAG.com | 1996-03-22 A0004 | Mustafa | 33333333 | Mf@CrAG.com | 2000-01-01 Note: The tables contain many more records than shown here. DOC is Date of Creation of an Article. As an employee of CAG, you are required to write the SQL queries for the following: (i) To display all the records from the Articles table in descending order of price. (ii) To display the details of Articles which were created in the year 2020. (iii) To display the structure of Artists table. (iv) (a) To display the name of all artists whose Article is Painting through Equi Join. OR (b) To display the name of all Artists whose Article is 'Painting' through Natural Join.
Simple Queries in SQL· 1 Mark· Q14· 2026 Board Paper
What will be the output of the query? SELECT MACHINE_ID, MACHINE_NAME FROM INVENTORY WHERE QUANTITY <= 100;
  1. (A)All columns of INVENTORY table with quantity greater than 100
  2. (B)ID and name of machines with quantity less than 100 from INVENTORY table
  3. (C)All columns of INVENTORY table with quantity greater than or equal to 100
  4. (D)ID and name of machines with quantity less than or equal to 100 from INVENTORY table.
Simple Queries in SQL· 1 Mark· Q16· 2026 Board Paper
Which aggregate function in SQL returns the smallest value from a column in a table?
  1. (A)MIN()
  2. (B)SMALL()
  3. (C)MAX()
  4. (D)LOWER()
Simple Queries in SQL· 4 Marks· Q32· 2026 Board Paper
STOCK table queries: (a) (i) Type and max Price for each Type. (ii) Increase Price by 0.5 where Type is 'F'. (iii) Total value (Qty * Price). (iv) Details where Code starts with 'A'. OR (b) Output of queries: (i) SELECT Volume, Qty, Price FROM STOCK WHERE Type IN ('F', 'D'); (ii) SELECT Code, Qty FROM STOCK WHERE Price BETWEEN 30 AND 50; (iii) SELECT DISTINCT Type FROM STOCK; (iv) SELECT Volume, count(*) FROM STOCK GROUP BY Volume;
Simple Queries in SQL· 1 Mark· Q14· 2025 Compartment Paper
Which of the following is not a valid relational operator used with WHERE clause in SQL?
  1. (A)>
  2. (B)<
  3. (C)=>
  4. (D)=
Simple Queries in SQL· 1 Mark· Q15· 2025 Compartment Paper
What is the default format of date in MySQL?
  1. (A)DD-MM-YYYY
  2. (B)MM-DD-YYYY
  3. (C)YYYY-MM-DD
  4. (D)YYYY-DD-MM
Simple Queries in SQL· 1 Mark· Q16· 2025 Compartment Paper
Ginni has created a table, SCORES in MySQL containing the following records: Ranveer: 50, Sukesh: 35, Mirza: 10, John: 51, Murugan: 70. Which of the following statements will give 10 as output?
  1. (A)SELECT MAX(Score) FROM Scores;
  2. (B)SELECT MIN(Score) FROM Scores;
  3. (C)SELECT SUM(Score) FROM Scores;
  4. (D)SELECT AVG(Score) FROM Scores;
Simple Queries in SQL· 4 Marks· Q32· 2025 Compartment Paper
Write SQL queries for STAFF table: (I) Display average salary of each department. (II) Insert record ('S333', 'GURMEET', 15000, 'ADMIN', 'CLERK'). (III) Display unique designations. (IV) Display details of staff whose name is of four letters. OR (b) Predict output of queries.
Simple Queries in SQL· 4 Marks· Q34· 2025 Compartment Paper
SQL Queries based on Work and Contractor tables: (I) Display all records from Work in alphabetical order of W_Name. (II) Display names of contractors where W_Amt > 15000. (III) Display structure of Work table. (IV) (a) Count total records in Work table OR (b) Delete contractors where Phone is NULL.
Simple Queries in SQL· 1 Mark· Q2· 2024 Sample Paper
In a table in MYSQL database, an attribute A of datatype varchar(20) has the value “Keshav”. The attribute B of datatype char(20) has value “Meenakshi”. How many characters are occupied by attribute A and attribute B?
  1. (A)a. 20,6
  2. (B)b. 6,20
  3. (C)c. 9,6
  4. (D)d. 6,9
Simple Queries in SQL· 3 Marks· Q27· 2024 Sample Paper
Consider the table CLUB given below and write the output of the SQL queries that follow. Table: CLUB CID | CNAME | AGE | GENDER | SPORTS | PAY | DOAPP 5246 | AMRITA | 35 | FEMALE | CHESS | 900 | 2006-03-27 4687 | SHYAM | 37 | MALE | CRICKET | 1300 | 2004-04-15 1245 | MEENA | 23 | FEMALE | VOLLEYBALL | 1000 | 2007-06-18 1622 | AMRIT | 28 | MALE | KARATE | 1000 | 2007-09-05 1256 | AMINA | 36 | FEMALE | CHESS | 1100 | 2003-08-15 1720 | MANJU | 33 | FEMALE | KARATE | 1250 | 2004-04-10 2321 | VIRAT | 35 | MALE | CRICKET | 1050 | 2005-04-30 (i) SELECT COUNT(DISTINCT SPORTS) FROM CLUB; (ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<"2006-04-30" AND CNAME LIKE "%NA"; (iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = "MALE" AND PAY BETWEEN 1000 AND 1200;
Simple Queries in SQL· 1 Mark· Q14· 2025 Sample Paper
What will be the output of the query? SELECT * FROM products WHERE product_name LIKE 'App%';
  1. (A)Details of all products whose names start with 'App'
  2. (B)Details of all products whose names end with 'App'
  3. (C)Names of all products whose names start with 'App'
  4. (D)Names of all products whose names end with 'App'
Simple Queries in SQL· 1 Mark· Q15· 2025 Sample Paper
In which datatype the value stored is padded with spaces to fit the specified length.
  1. (A)DATE
  2. (B)VARCHAR
  3. (C)FLOAT
  4. (D)CHAR
Simple Queries in SQL· 1 Mark· Q16· 2025 Sample Paper
Which aggregate function can be used to find the cardinality of a table?
  1. (A)sum()
  2. (B)count()
  3. (C)avg()
  4. (D)max()
Simple Queries in SQL· 4 Marks· Q32· 2025 Sample Paper
Consider the table ORDERS as given below O_Id | C_Name | Product | Quantity | Price 1001 | Jitendra | Laptop | 1 | 12000 1002 | Mustafa | Smartphone | 2 | 10000 1003 | Dhwani | Headphone | 1 | 1500 Note: The table contains many more records than shown here. A) Write the following queries: (I) To display the total Quantity for each Product, excluding Products with total Quantity less than 5. (II) To display the orders table sorted by total price in descending order. (III) To display the distinct customer names from the Orders table. (IV) Display the sum of Price of all the orders for which the quantity is null. OR B) Write the output (I) Select c_name, sum(quantity) as total_quantity from orders group by c_name; (II) Select * from orders where product like '%phone%'; (III) Select o_id, c_name, product, quantity, price from orders where price between 1500 and 12000; (IV) Select max(price) from orders;
Simple Queries in SQL· 4 Marks· Q32· 2026 Sample Paper
Consider the table SALES as given below: sales_id | customer_name | product | quantity_sold | price S001 | John Doe | Laptop | 5 | 50000 S002 | Jane Smith | Smartphone | 10 | 30000 S003 | Michael Lee | Tablet | 3 | 15000 S004 | Sarah Brown | Headphones | 7 | 2000 S005 | Emily Davis | Smartwatch | 8 | 8000 S006 | David | Smartwatch | 3 | 16000 S007 | Mark | Tablet | 5 | 34000 A. Write the following queries: I. To display the total quantity sold for each product whose total quantity sold exceeds 12. II. To display the records of SALES table sorted by Product name in descending order. III. To display the distinct Product names from the SALES table. IV. To display the records of customers whose names end with the letter 'e'. OR B. Predict the output of the following: I. SELECT * FROM Sales where product='Tablet'; II. SELECT sales_id, customer_name FROM Sales WHERE product LIKE 'S%'; III. SELECT COUNT(*) FROM Sales WHERE product in ('Laptop', 'Tablet'); IV. SELECT AVG(price) FROM Sales where product='Tablet';
Simple Queries in SQL· 1 Mark· Q9· 2027 Sample Paper
Which MySQL query will display all employees whose salaries are between 90,000 and 100,000 (including limits)?
  1. (A)SELECT * FROM Employees WHERE salary > 90000 AND salary < 100000;
  2. (B)SELECT * FROM Employees WHERE salary IN (90000, 100000);
  3. (C)SELECT * FROM Employees WHERE salary BETWEEN 90000 AND 100000;
  4. (D)SELECT * FROM Employees WHERE salary = 90000 OR salary = 100000;
Simple Queries in SQL· 1 Mark· Q21· 2027 Sample Paper
Assertion (A): The MySQL query SELECT Student_Name FROM Student WHERE Guardian_Phone IS NULL; displays the names of students whose guardian phone number is not recorded. Reason (R): In MySQL, you can also use = to check for NULL values; it is equivalent to IS NULL to identify columns with no value.
  1. (A)Both A and R are True and R is the correct explanation for A.
  2. (B)Both A and R are True and R is not the correct explanation for A.
  3. (C)A is True but R is False.
  4. (D)A is False but R is True.
Simple Queries in SQL· 4 Marks· Q32· 2027 Sample Paper
Consider the table TECH_EVENT_REG as given below: A. Write the following queries: I. To display the number of participants in each event where the number of participants is greater than 1. II. To display the distinct event names available in the Tech Event. III. To display details of participants whose names contain the letters ‘an’. IV. To display all records of TECH_EVENT_REG sorted by participant_name in descending order. OR B. Predict the output of the following: I. Select participant_name, event_name from tech_event_reg where grade = 11; II. Select event_name, count(*) from tech_event_reg group by event_name; III. Select participant_name from tech_event_reg where event_name like '%challenge'; IV. Select max(reg_fee) from tech_event_reg where grade in (9, 10);