On this page
SQL questions in CBSE computer science are some of the most reliable marks in the paper, because the language is small and the questions follow patterns. They are also easy to lose to one wrong keyword. This post builds two small tables and runs every query type the syllabus lists, with the output of each, then covers the mistakes examiners look for.
What SQL does the CBSE syllabus include?
The CBSE Computer Science curriculum for Class XII (2026-27) gives Database Management 20 of the 70 theory marks. Its SQL list covers creating and altering tables, insert, update, delete, select, operators, aliasing, distinct, where, in, between, order by, null with is null and is not null, like, aggregate functions (max, min, avg, sum, count), group by, having, and joins: cartesian product, equi-join and natural join. The practical exam also has a lab test with four SQL queries. The NCERT chapter on SQL uses MySQL, and so does this post.
Here are the two tables.
CREATE TABLE STUDENT (RollNo INT PRIMARY KEY, Name VARCHAR(20),
Section CHAR(1), Marks INT, City VARCHAR(20));
INSERT INTO STUDENT VALUES
(1, 'Asha', 'A', 82, 'Pune'), (2, 'Ravi', 'B', 64, 'Delhi'),
(3, 'Meera', 'A', 91, 'Pune'), (4, 'Kabir', 'B', 75, NULL),
(5, 'Anil', 'A', 58, 'Delhi');
CREATE TABLE CLUB (RollNo INT, ClubName VARCHAR(20));
INSERT INTO CLUB VALUES (1, 'Robotics'), (3, 'Quiz'), (4, 'Robotics');How do SELECT and WHERE filter rows?
SELECT Name, Marks FROM STUDENT WHERE Marks BETWEEN 60 AND 80;
SELECT Name FROM STUDENT WHERE Name LIKE 'A%';
SELECT Name FROM STUDENT WHERE City IN ('Pune', 'Delhi');
SELECT Name, Marks FROM STUDENT ORDER BY Marks DESC;
SELECT DISTINCT City FROM STUDENT;The first returns Ravi (64) and Kabir (75). BETWEEN includes both ends.
The second returns Asha and Anil. In LIKE, % matches any number of characters and _ matches exactly one.
The third returns Asha, Ravi, Meera and Anil, but not Kabir, whose city is NULL.
The fourth lists Meera 91, Asha 82, Kabir 75, Ravi 64, Anil 58.
The fifth returns Pune, Delhi and NULL, since DISTINCT treats NULL as one value.
How do you test for NULL?
SELECT Name FROM STUDENT WHERE City IS NULL; -- Kabir
SELECT Name FROM STUDENT WHERE City = NULL; -- no rowsThe MySQL manual on NULL says plainly: "You cannot use arithmetic comparison operators such as =, <, or <> to test for NULL." Any comparison with NULL gives NULL, so the second query returns nothing. The 2026-27 CBSE sample question paper has an assertion-reason question built on exactly this point.
How do aggregate functions and GROUP BY work?
SELECT COUNT(*), COUNT(City) FROM STUDENT; -- 5, 4
SELECT Section, COUNT(*), AVG(Marks), MAX(Marks)
FROM STUDENT GROUP BY Section;COUNT(*) counts rows; COUNT(City) skips the NULL. The MySQL manual on aggregate functions states that aggregate functions ignore NULL values unless stated otherwise, and that COUNT(*) counts rows whether or not they contain NULL.
The GROUP BY query gives one row per section: A has 3 students, average 77, highest 91; B has 2 students, average 69.5, highest 75. Section A's average is (82 + 91 + 58) / 3 = 231 / 3 = 77.
When do you use HAVING instead of WHERE?
WHERE filters rows before grouping. HAVING filters groups after.
SELECT City, COUNT(*) FROM STUDENT GROUP BY City HAVING COUNT(*) > 1;
SELECT Section, AVG(Marks) FROM STUDENT WHERE Marks > 60 GROUP BY Section;The first returns Pune 2 and Delhi 2. The second drops Anil (58) before grouping, so Section A's average becomes (82 + 91) / 2 = 86.5, and B stays 69.5. The MySQL SELECT reference notes that HAVING "can refer to aggregate functions, which the WHERE clause cannot", and advises: "Do not use HAVING for items that should be in the WHERE clause."
How do joins combine two tables?
SELECT COUNT(*) FROM STUDENT, CLUB; -- 15
SELECT S.Name, C.ClubName FROM STUDENT S, CLUB C
WHERE S.RollNo = C.RollNo;
SELECT * FROM STUDENT NATURAL JOIN CLUB;Cartesian product. Every student is paired with every club row. NCERT explains that the result's degree (columns) is the sum of the two degrees and its cardinality (rows) is the product: 5 + 2 = 7 columns and 5 × 3 = 15 rows.
Equi-join. The WHERE condition keeps matching RollNo pairs: Asha with Robotics, Meera with Quiz, Kabir with Robotics. The aliases S and C remove ambiguity, since both tables have RollNo.
Natural join. It joins on the common column and, as NCERT notes, shows that column only once.
What mistakes cost marks in SQL?
= NULL instead of IS NULL.
Aggregates in WHERE, such as WHERE COUNT(*) > 1.
Confusing ALTER and UPDATE. ALTER changes the table's structure; UPDATE changes data in rows.
Confusing DELETE and DROP. DELETE removes rows; DROP TABLE removes the whole table.
Missing quotes around text and date values.
A practice routine for SQL
Install MySQL or use the school lab, and type the two tables above.
Each day: Write five queries from the syllabus list, predict the output on paper, then run them.
Twice a week: Do the SQL questions from a sample paper, including the predict-the-output kind.
Before the practical: Prepare your five query sets for the report file, on one table and on two, and read our notes on the board practical exam and viva. The Python side of the paper is in the Python basics that are tested.
If a database idea such as a foreign key is still fuzzy, the Fermi Concept Library has every concept in computing with its own lesson, so you can understand the model before writing the query.
Type the two tables above into MySQL today and run every query in this post.



