CBSE Class 12 · Informatics Practices, code 065 · Unit 2, 25 marks

Class 12 IP SQL questions with answers, run on MySQL before you read them.

A sky-watching club keeps two tables: what can be seen, and who saw it. These class 12 IP SQL questions with answers ask them everything Unit 2 of CBSE 065 allows, from a one-mark LENGTH() to a four-mark join with HAVING. Cover the answer, write yours on paper, then open the MySQL grid and compare column headings as well as values.

Live one to one · 40 original questions · real MySQL grids · your own days and hours

Start here

Courses with a live MySQL window

The first teaches Unit 2 inside the whole IP syllabus. The second takes the same grouping idea into pandas. The third is for a student who wants months of SQL and nothing else.

Ans. The short version

Class 12 IP SQL questions with answers should cover Unit 2 of CBSE Informatics Practices (065), which carries 25 of the 70 theory marks in 2026-27: math functions (POWER, ROUND, MOD), text functions such as MID, INSTR and TRIM, date functions such as MONTHNAME and DAYNAME, aggregate functions, GROUP BY, HAVING, ORDER BY, equi-join of two tables, and the Class 11 commands. This page has 40 original questions with MySQL output. Modern Age Coders teaches the unit live, personalised one to one at your own timing; a priority demo lets you try one class first.

Q. Which functions can be asked?

SQL functions for Class 12 IP: the full list, each one tested

The 065 syllabus names 3 math, 10 text, 7 date and 5 aggregate functions. The first three kinds work on one row and give one value per row; an aggregate function takes many rows and gives one value.

Math and date functions

CallMySQL returnsRemember
POWER(2, 5)32Base first, then the power
ROUND(2745.638, 2)2745.64Two places after the point
ROUND(2745.638)2746No second argument means whole number
ROUND(2745.638, -2)2700Negative means hundreds
MOD(4, 29)4Smaller divided by larger: itself
DATE('2026-11-14 21:40:00')2026-11-14Drops the time
DAY('2027-03-31')31A number
MONTH('2027-03-31')3A number
MONTHNAME('2026-11-14')NovemberA word
YEAR('2027-03-31')2027Four digits
DAYNAME('2026-11-14')SaturdayA word
NOW()the present date and timeNo argument, but the brackets stay

Text functions

CallMySQL returnsRemember
UPPER('Saturn')SATURNSame as UCASE()
LOWER('Saturn')saturnSame as LCASE()
MID('Saturn', 3, 2)tuStart, then how many; counting begins at 1
SUBSTR('Saturn', -3)urnNegative start counts from the end
LENGTH('Orion Nebula')12Spaces count
LEFT('Saturn', 3)SatFrom the left end
RIGHT('Saturn', 3)urnFrom the right end
INSTR('Andromeda', 'd')3First match only
INSTR('Saturn', 'x')0Not found is 0, not an error
TRIM(' Saturn ')SaturnBoth ends; LTRIM and RTRIM do one each

MID, SUBSTR and SUBSTRING are three names for one function. Python counts from 0 and SQL from 1, which is why a student strong in pandas is often one letter out here.

Aggregate functions: MAX(), MIN(), AVG(), SUM() and COUNT(), plus COUNT(*). All except COUNT(*) skip NULL.

Q. Can you get the column heading right too?

Class 12 IP SQL practice questions on text, math and date functions

Sixteen questions, all on the two tables below. Write the command for a task, and the heading with the value for an output question.

Query and result6 rows
SELECT * FROM SKYOBJ;

+------+--------------+---------+--------+
| Code | OName        | Kind    | Points |
+------+--------------+---------+--------+
| JUP  | Jupiter      | Planet  |      3 |
| M13  | Hercules     | Cluster |      8 |
| M31  | Andromeda    | Galaxy  |     10 |
| M42  | Orion Nebula | Nebula  |      6 |
| M45  | Pleiades     | Cluster |      4 |
| SAT  | Saturn       | Planet  |      5 |
+------+--------------+---------+--------+
Query and result9 rows
SELECT * FROM SKYLOG;

+-------+---------------+------+------------+-------+--------+
| LogNo | Watcher       | Code | LDate      | Hours | Photos |
+-------+---------------+------+------------+-------+--------+
|     1 | Zoya Khan     | M45  | 2026-01-16 |  1.75 |     12 |
|     2 | Tenzin Bhutia | M42  | 2026-01-23 |  2.40 |     30 |
|     3 | Meera Das     | JUP  | 2026-02-06 |  0.85 |   NULL |
|     4 | Zoya Khan     | M42  | 2026-02-13 |  3.15 |     26 |
|     5 | Aarush Nair   | JUP  | 2026-03-07 |  1.25 |      9 |
|     6 | Tenzin Bhutia | M31  | 2026-10-10 |  2.65 |   NULL |
|     7 | Meera Das     | M45  | 2026-10-17 |  1.50 |     14 |
|     8 | Aarush Nair   | M31  | 2026-11-07 |  2.05 |     18 |
|     9 | Zoya Khan     | SAT  | 2026-11-14 |  0.95 |      7 |
+-------+---------------+------+------------+-------+--------+
Commands that build the tables, so you can run every query yourself
Create and fillMySQL
CREATE TABLE SKYOBJ (
  Code CHAR(3) PRIMARY KEY,
  OName VARCHAR(20),
  Kind VARCHAR(10),
  Points INT);
INSERT INTO SKYOBJ VALUES
('M31','Andromeda','Galaxy',10),
('M42','Orion Nebula','Nebula',6),
('M45','Pleiades','Cluster',4),
('JUP','Jupiter','Planet',3),
('SAT','Saturn','Planet',5),
('M13','Hercules','Cluster',8);
CREATE TABLE SKYLOG (
  LogNo INT PRIMARY KEY,
  Watcher VARCHAR(15),
  Code CHAR(3),
  LDate DATE,
  Hours DECIMAL(4,2),
  Photos INT);
INSERT INTO SKYLOG VALUES
(1,'Zoya Khan','M45','2026-01-16',1.75,12),
(2,'Tenzin Bhutia','M42','2026-01-23',2.40,30),
(3,'Meera Das','JUP','2026-02-06',0.85,NULL),
(4,'Zoya Khan','M42','2026-02-13',3.15,26),
(5,'Aarush Nair','JUP','2026-03-07',1.25,9),
(6,'Tenzin Bhutia','M31','2026-10-10',2.65,NULL),
(7,'Meera Das','M45','2026-10-17',1.50,14),
(8,'Aarush Nair','M31','2026-11-07',2.05,18),
(9,'Zoya Khan','SAT','2026-11-14',0.95,7);

Text functions

  1. Q1. Show the name of the watcher of log 2 in capital letters, with the number of characters in it. [1]
    Answer
    Query and resulttext
    SELECT UPPER(Watcher), LENGTH(Watcher)
    FROM SKYLOG
    WHERE LogNo = 2;
    
    +----------------+-----------------+
    | UPPER(Watcher) | LENGTH(Watcher) |
    +----------------+-----------------+
    | TENZIN BHUTIA  |              13 |
    +----------------+-----------------+

    UCASE() is the same function. LENGTH counted the space, so the answer is 13 and not 12.

  2. Q2. Show the first three letters of each planet's name in small letters. [1]
    Answer
    Query and resultnested
    SELECT LOWER(LEFT(OName, 3))
    FROM SKYOBJ
    WHERE Kind = 'Planet';
    
    +-----------------------+
    | LOWER(LEFT(OName, 3)) |
    +-----------------------+
    | jup                   |
    | sat                   |
    +-----------------------+

    The inner function works first. LEFT(LOWER(OName), 3) would give the same text.

  3. Q3. Write the output. Be careful with the first column. [1]
    Querypredict it
    SELECT MID(OName, 3, 4), RIGHT(Kind, 3)
    FROM SKYOBJ
    WHERE Code = 'M42';
    Answer
    Resultfour characters
    +------------------+----------------+
    | MID(OName, 3, 4) | RIGHT(Kind, 3) |
    +------------------+----------------+
    | ion              | ula            |
    +------------------+----------------+

    Characters 3 to 6 of Orion Nebula are i, o, n and a space. The grid hides the space; LENGTH() of that value returns 4. In an answer book, write it as "ion " with the gap shown.

  4. Q4. In how many rows will the second column be 0? [1]
    Querypredict it
    SELECT OName, INSTR(OName, 'e')
    FROM SKYOBJ;
    Answer
    Resultposition of the first match
    +--------------+-------------------+
    | OName        | INSTR(OName, 'e') |
    +--------------+-------------------+
    | Jupiter      |                 6 |
    | Hercules     |                 2 |
    | Andromeda    |                 7 |
    | Orion Nebula |                 8 |
    | Pleiades     |                 3 |
    | Saturn       |                 0 |
    +--------------+-------------------+

    One row. Saturn has no letter e, so INSTR gives 0. Elsewhere it gives the position of the first e.

  5. Q5. Display only the first names of those who logged after October 2026. [2]
    Answer
    Query and resultINSTR inside LEFT
    SELECT LEFT(Watcher, INSTR(Watcher, ' ') - 1)
    FROM SKYLOG
    WHERE LDate > '2026-10-31';
    
    +----------------------------------------+
    | LEFT(Watcher, INSTR(Watcher, ' ') - 1) |
    +----------------------------------------+
    | Aarush                                 |
    | Zoya                                   |
    +----------------------------------------+

    INSTR finds the space. One less than that is the number of letters to keep. Names without a space would come out blank.

  6. Q6. For the objects whose code starts with M, show the code and the part after the M. [2]
    Answer
    Query and resulttwo arguments
    SELECT Code, SUBSTR(Code, 2)
    FROM SKYOBJ
    WHERE LEFT(Code, 1) = 'M';
    
    +------+-----------------+
    | Code | SUBSTR(Code, 2) |
    +------+-----------------+
    | M13  | 13              |
    | M31  | 31              |
    | M42  | 42              |
    | M45  | 45              |
    +------+-----------------+

    With no third argument, SUBSTR runs to the end. LEFT(Code, 1) = 'M' does the filtering with a listed function.

  7. Q7. Write the output. The string has two spaces before Saturn and one after. [2]
    Querypredict it
    SELECT LENGTH('  Saturn '), LENGTH(LTRIM('  Saturn ')),
           LENGTH(RTRIM('  Saturn ')), LENGTH(TRIM('  Saturn '));
    Answer
    Resultlengths
    +---------------------+----------------------------+----------------------------+---------------------------+
    | LENGTH('  Saturn ') | LENGTH(LTRIM('  Saturn ')) | LENGTH(RTRIM('  Saturn ')) | LENGTH(TRIM('  Saturn ')) |
    +---------------------+----------------------------+----------------------------+---------------------------+
    |                   9 |                          7 |                          8 |                         6 |
    +---------------------+----------------------------+----------------------------+---------------------------+

    Six letters and three spaces make 9. LTRIM removes two, RTRIM one, TRIM all three. None of them touches a space between words.

  8. Q8. Display the objects whose names end with the letter s. [1]
    Answer
    Query and resultRIGHT
    SELECT OName
    FROM SKYOBJ
    WHERE RIGHT(OName, 1) = 's';
    
    +----------+
    | OName    |
    +----------+
    | Hercules |
    | Pleiades |
    +----------+

    RIGHT(OName, 1) is the last letter. The official scheme uses this same idea for such a question.

Math and date functions

  1. Q9. Write the output. [2]
    Querypredict it
    SELECT POWER(2, 5), MOD(29, 4),
           ROUND(746.28, 1), ROUND(746.28, -1);
    Answer
    Resulthalf a mark each
    +-------------+------------+------------------+-------------------+
    | POWER(2, 5) | MOD(29, 4) | ROUND(746.28, 1) | ROUND(746.28, -1) |
    +-------------+------------+------------------+-------------------+
    |          32 |          1 |            746.3 |               750 |
    +-------------+------------+------------------+-------------------+

    A negative second argument rounds to the left of the point: -1 means tens. 29 = 4 x 7 + 1, so MOD is 1.

  2. Q10. Show log number and hours for the Orion Nebula (M42), with the hours to one decimal place and to a whole number. [2]
    Answer
    Query and resultROUND twice
    SELECT LogNo, Hours, ROUND(Hours, 1), ROUND(Hours)
    FROM SKYLOG
    WHERE Code = 'M42';
    
    +-------+-------+-----------------+--------------+
    | LogNo | Hours | ROUND(Hours, 1) | ROUND(Hours) |
    +-------+-------+-----------------+--------------+
    |     2 |  2.40 |             2.4 |            2 |
    |     4 |  3.15 |             3.2 |            3 |
    +-------+-------+-----------------+--------------+

    ROUND with one argument rounds to a whole number. 3.15 becomes 3.2 because the digit after the kept place is 5.

  3. Q11. Display every fourth log, that is numbers divisible by 4. [1]
    Answer
    Query and resultMOD in WHERE
    SELECT LogNo, Watcher
    FROM SKYLOG
    WHERE MOD(LogNo, 4) = 0;
    
    +-------+-------------+
    | LogNo | Watcher     |
    +-------+-------------+
    |     4 | Zoya Khan   |
    |     8 | Aarush Nair |
    +-------+-------------+

    MOD(LogNo, 4) = 0 tests divisibility. For odd numbers use MOD(LogNo, 2) = 1.

  4. Q12. Show each planet with the square of its points. [1]
    Answer
    Query and resultPOWER
    SELECT OName, POWER(Points, 2)
    FROM SKYOBJ
    WHERE Kind = 'Planet';
    
    +---------+------------------+
    | OName   | POWER(Points, 2) |
    +---------+------------------+
    | Jupiter |                9 |
    | Saturn  |               25 |
    +---------+------------------+

    POWER(Points, 2) is Points multiplied by itself. MySQL accepts POW too, but write the name in the syllabus.

  5. Q13. For the November logs, show the log number, day, month name and weekday. [2]
    Answer
    Query and resultfour date functions
    SELECT LogNo, DAY(LDate), MONTHNAME(LDate), DAYNAME(LDate)
    FROM SKYLOG
    WHERE MONTH(LDate) = 11;
    
    +-------+------------+------------------+----------------+
    | LogNo | DAY(LDate) | MONTHNAME(LDate) | DAYNAME(LDate) |
    +-------+------------+------------------+----------------+
    |     8 |          7 | November         | Saturday       |
    |     9 |         14 | November         | Saturday       |
    +-------+------------+------------------+----------------+

    MONTH() returns a number, so it is compared with 11 and not with a word. MONTHNAME() would be compared with 'November'.

  6. Q14. Who watched for more than 2 hours on a Friday, and on which date? [2]
    Answer
    Query and resultDAYNAME in WHERE
    SELECT Watcher, LDate
    FROM SKYLOG
    WHERE DAYNAME(LDate) = 'Friday' AND Hours > 2;
    
    +---------------+------------+
    | Watcher       | LDate      |
    +---------------+------------+
    | Tenzin Bhutia | 2026-01-23 |
    | Zoya Khan     | 2026-02-13 |
    +---------------+------------+

    The weekday is worked out from the date, so it needs no column of its own.

  7. Q15. Write the output. [1]
    Querypredict it
    SELECT DATE('2026-11-14 21:40:00'),
           DAYNAME('2027-03-31'), YEAR('2027-03-31');
    Answer
    Resultthree values
    +-----------------------------+-----------------------+--------------------+
    | DATE('2026-11-14 21:40:00') | DAYNAME('2027-03-31') | YEAR('2027-03-31') |
    +-----------------------------+-----------------------+--------------------+
    | 2026-11-14                  | Wednesday             |               2027 |
    +-----------------------------+-----------------------+--------------------+

    DATE() cuts the time away. The second and third columns describe the day of your theory paper.

  8. Q16. How is NOW() different from the other date functions here? [1]
    Answer It takes no argument and returns the current date and time of the computer, so its output changes every second. DATE(NOW()) gives only today's date.

Q. What does MySQL do first?

GROUP BY and HAVING in Class 12 IP, one step at a time

GROUP BY collects rows that share a value and gives one result row for each collection. HAVING then keeps or drops whole groups, as WHERE does for single rows.

Read this requirement: for sessions of at least one hour, show each watcher's number of sessions and total hours, only if the total is above 3 hours, highest first. Here is the query growing, with the rows left after each stage.

Query and result1. WHERE picks rows
SELECT Watcher, Hours
FROM SKYLOG
WHERE Hours >= 1
ORDER BY Watcher;

+---------------+-------+
| Watcher       | Hours |
+---------------+-------+
| Aarush Nair   |  1.25 |
| Aarush Nair   |  2.05 |
| Meera Das     |  1.50 |
| Tenzin Bhutia |  2.40 |
| Tenzin Bhutia |  2.65 |
| Zoya Khan     |  1.75 |
| Zoya Khan     |  3.15 |
+---------------+-------+

Logs 3 and 9 are under an hour, so seven rows remain. Sorted here only so that you can see the future groups.

Query and result2. GROUP BY makes groups
SELECT Watcher, COUNT(*), SUM(Hours)
FROM SKYLOG
WHERE Hours >= 1
GROUP BY Watcher;

+---------------+----------+------------+
| Watcher       | COUNT(*) | SUM(Hours) |
+---------------+----------+------------+
| Zoya Khan     |        2 |       4.90 |
| Tenzin Bhutia |        2 |       5.05 |
| Aarush Nair   |        2 |       3.30 |
| Meera Das     |        1 |       1.50 |
+---------------+----------+------------+

Four watchers, four rows. Zoya has two sessions here, not three.

Query and result3. HAVING drops groups
SELECT Watcher, COUNT(*), SUM(Hours)
FROM SKYLOG
WHERE Hours >= 1
GROUP BY Watcher
HAVING SUM(Hours) > 3;

+---------------+----------+------------+
| Watcher       | COUNT(*) | SUM(Hours) |
+---------------+----------+------------+
| Zoya Khan     |        2 |       4.90 |
| Tenzin Bhutia |        2 |       5.05 |
| Aarush Nair   |        2 |       3.30 |
+---------------+----------+------------+

Meera, with 1.50 hours, is gone.

Query and result4. ORDER BY sorts
SELECT Watcher, COUNT(*), SUM(Hours)
FROM SKYLOG
WHERE Hours >= 1
GROUP BY Watcher
HAVING SUM(Hours) > 3
ORDER BY SUM(Hours) DESC;

+---------------+----------+------------+
| Watcher       | COUNT(*) | SUM(Hours) |
+---------------+----------+------------+
| Tenzin Bhutia |        2 |       5.05 |
| Zoya Khan     |        2 |       4.90 |
| Aarush Nair   |        2 |       3.30 |
+---------------+----------+------------+

Sorting is always last, on rows that have survived everything else.

Point of differenceWHEREHAVING
Works onsingle rowsgroups
Happensbefore groupingafter grouping
Aggregate function inside?not allowedallowed, and usual
Needs GROUP BY?noused with it
In the query aboveWHERE Hours >= 1HAVING SUM(Hours) > 3
  1. Q17. Write the output, and say why the first two numbers differ. [2]
    Querypredict it
    SELECT COUNT(*), COUNT(Photos), SUM(Photos), AVG(Photos)
    FROM SKYLOG;
    Answer
    ResultNULL is left out
    +----------+---------------+-------------+-------------+
    | COUNT(*) | COUNT(Photos) | SUM(Photos) | AVG(Photos) |
    +----------+---------------+-------------+-------------+
    |        9 |             7 |         116 |     16.5714 |
    +----------+---------------+-------------+-------------+

    Nine rows, but two have no photo count. COUNT(Photos), SUM and AVG ignore NULL, so the average is 116 divided by 7, not by 9.

  2. Q18. Display the earliest and the latest date in the log, and the longest session. [1]
    Answer
    Query and resultworks on dates too
    SELECT MIN(LDate), MAX(LDate), MAX(Hours)
    FROM SKYLOG;
    
    +------------+------------+------------+
    | MIN(LDate) | MAX(LDate) | MAX(Hours) |
    +------------+------------+------------+
    | 2026-01-16 | 2026-11-14 |       3.15 |
    +------------+------------+------------+

    MIN of a date column is the earliest date.

  3. Q19. For each kind of object, show how many there are and the highest points. [2]
    Answer
    Query and resultone row per kind
    SELECT Kind, COUNT(*), MAX(Points)
    FROM SKYOBJ
    GROUP BY Kind
    ORDER BY Kind;
    
    +---------+----------+-------------+
    | Kind    | COUNT(*) | MAX(Points) |
    +---------+----------+-------------+
    | Cluster |        2 |           8 |
    | Galaxy  |        1 |          10 |
    | Nebula  |        1 |           6 |
    | Planet  |        2 |           5 |
    +---------+----------+-------------+

    The column after GROUP BY is the one you show beside the aggregate functions.

  4. Q20. Show the months that have more than one log, with the number of logs and the hours. [3]
    Answer
    Query and resultgrouping by a function
    SELECT MONTHNAME(LDate), COUNT(*), SUM(Hours)
    FROM SKYLOG
    GROUP BY MONTHNAME(LDate)
    HAVING COUNT(*) > 1;
    
    +------------------+----------+------------+
    | MONTHNAME(LDate) | COUNT(*) | SUM(Hours) |
    +------------------+----------+------------+
    | January          |        2 |       4.15 |
    | February         |        2 |       4.00 |
    | October          |        2 |       4.15 |
    | November         |        2 |       3.00 |
    +------------------+----------+------------+

    GROUP BY can use a function of a column. March has a single log, so HAVING drops it.

  1. Q21. Write the output. [2]
    Querypredict it
    SELECT Code, MIN(Hours), MAX(Hours)
    FROM SKYLOG
    GROUP BY Code
    HAVING COUNT(*) = 2
    ORDER BY Code;
    Answer
    Resultexactly two logs
    +------+------------+------------+
    | Code | MIN(Hours) | MAX(Hours) |
    +------+------------+------------+
    | JUP  |       0.85 |       1.25 |
    | M31  |       2.05 |       2.65 |
    | M42  |       2.40 |       3.15 |
    | M45  |       1.50 |       1.75 |
    +------+------------+------------+

    SAT has one log and is dropped. The condition is on COUNT(*) although COUNT(*) is not displayed, and that is allowed.

  2. Q22. Write the output. Which group shows the difference between COUNT(*) and COUNT(Photos)? [3]
    Querypredict it
    SELECT Code, COUNT(*), COUNT(Photos), AVG(Photos)
    FROM SKYLOG
    GROUP BY Code
    ORDER BY Code;
    Answer
    ResultJUP and M31
    +------+----------+---------------+-------------+
    | Code | COUNT(*) | COUNT(Photos) | AVG(Photos) |
    +------+----------+---------------+-------------+
    | JUP  |        2 |             1 |      9.0000 |
    | M31  |        2 |             1 |     18.0000 |
    | M42  |        2 |             2 |     28.0000 |
    | M45  |        2 |             2 |     13.0000 |
    | SAT  |        1 |             1 |      7.0000 |
    +------+----------+---------------+-------------+

    JUP and M31 have two logs but one photo count each. Their average is that single number divided by 1.

  3. Q23. List the objects by kind, and within a kind from most points to least. [1]
    Answer
    Query and resulttwo sort keys
    SELECT Kind, OName, Points
    FROM SKYOBJ
    ORDER BY Kind, Points DESC;
    
    +---------+--------------+--------+
    | Kind    | OName        | Points |
    +---------+--------------+--------+
    | Cluster | Hercules     |      8 |
    | Cluster | Pleiades     |      4 |
    | Galaxy  | Andromeda    |     10 |
    | Nebula  | Orion Nebula |      6 |
    | Planet  | Saturn       |      5 |
    | Planet  | Jupiter      |      3 |
    +---------+--------------+--------+

    DESC belongs only to Points. Kind stays ascending, which is the default.

  4. Q24. Find the error and correct the query. [2]
    Queryhas an error
    SELECT Watcher, COUNT(*)
    FROM SKYLOG
    WHERE COUNT(*) > 2
    GROUP BY Watcher;
    Answer
    Resultwhat MySQL says
    ERROR 1111 (HY000): Invalid use of group function
    Query and resultcorrected
    SELECT Watcher, COUNT(*)
    FROM SKYLOG
    GROUP BY Watcher
    HAVING COUNT(*) > 2;
    
    +-----------+----------+
    | Watcher   | COUNT(*) |
    +-----------+----------+
    | Zoya Khan |        3 |
    +-----------+----------+

    WHERE looks at one row at a time, before any group exists, so it cannot use COUNT(*). Conditions on a group go in HAVING, after GROUP BY.

One more query worth testing on your own machine is SELECT Watcher, LDate, COUNT(*) FROM SKYLOG GROUP BY Watcher;. MySQL 26 refuses it, because a watcher has many dates and only one can fill the cell. Show the grouped column and aggregate functions, nothing else. The same thinking in Python is on DataFrame for Class 12 IP.

Q. How do two tables become one answer?

Equi-join questions for Class 12 IP, with the rows they return

An equi-join pairs the rows of two tables where a column in one equals a column in the other. In 065 it is written with both table names after FROM and the equality in WHERE.

1. Find the shared column

Here it is Code. It is the primary key of SKYOBJ, so it is unique there. In SKYLOG the same code appears once for every log.

2. Write the equality

SKYLOG.Code = SKYOBJ.Code. With two tables you need one such condition. Other conditions follow with AND.

3. Say whose column it is

A name found in both tables must carry its table name, wherever it appears in the query.

  1. Q25. How many rows does this return, and why? [1]
    Querypredict it
    SELECT COUNT(*)
    FROM SKYLOG, SKYOBJ;
    Answer
    Resultno join condition
    +----------+
    | COUNT(*) |
    +----------+
    |       54 |
    +----------+

    9 logs x 6 objects = 54. Every log is paired with every object, so 45 of the pairs are meaningless.

  2. Q26. Display watcher, object name and hours for sessions longer than 2 hours. [2]
    Answer
    Query and resultequi-join plus a condition
    SELECT Watcher, OName, Hours
    FROM SKYLOG, SKYOBJ
    WHERE SKYLOG.Code = SKYOBJ.Code
      AND Hours > 2;
    
    +---------------+--------------+-------+
    | Watcher       | OName        | Hours |
    +---------------+--------------+-------+
    | Tenzin Bhutia | Orion Nebula |  2.40 |
    | Zoya Khan     | Orion Nebula |  3.15 |
    | Tenzin Bhutia | Andromeda    |  2.65 |
    | Aarush Nair   | Andromeda    |  2.05 |
    +---------------+--------------+-------+

    One mark for both tables in FROM with the columns, one for the join condition together with the filter.

  3. Q27. Display the log number, object name and weekday of every planet log, in log order. [2]
    Answer
    Query and resultfunction on a joined row
    SELECT LogNo, OName, DAYNAME(LDate)
    FROM SKYLOG, SKYOBJ
    WHERE SKYLOG.Code = SKYOBJ.Code
      AND Kind = 'Planet'
    ORDER BY LogNo;
    
    +-------+---------+----------------+
    | LogNo | OName   | DAYNAME(LDate) |
    +-------+---------+----------------+
    |     3 | Jupiter | Friday         |
    |     5 | Jupiter | Saturday       |
    |     9 | Saturn  | Saturday       |
    +-------+---------+----------------+

    Kind is in SKYOBJ and LDate in SKYLOG. After the join they stand in one row.

  4. Q28. This query fails. Why? [1]
    Queryhas an error
    SELECT Watcher, Code, OName
    FROM SKYLOG, SKYOBJ
    WHERE SKYLOG.Code = SKYOBJ.Code;
    Answer
    Resultwhat MySQL says
    ERROR 1052 (23000): Column 'Code' in field list is ambiguous

    Code is in both tables. Write SKYLOG.Code or SKYOBJ.Code; either is right, since they are equal in every joined row.

  1. Q29. For each kind of object, show the number of logs and total hours, highest hours first. [3]
    Answer
    Query and resultjoin, then group
    SELECT Kind, COUNT(*), SUM(Hours)
    FROM SKYLOG, SKYOBJ
    WHERE SKYLOG.Code = SKYOBJ.Code
    GROUP BY Kind
    ORDER BY SUM(Hours) DESC;
    
    +---------+----------+------------+
    | Kind    | COUNT(*) | SUM(Hours) |
    +---------+----------+------------+
    | Nebula  |        2 |       5.55 |
    | Galaxy  |        2 |       4.70 |
    | Cluster |        2 |       3.25 |
    | Planet  |        3 |       3.05 |
    +---------+----------+------------+

    The join condition goes in WHERE, before GROUP BY. The two clusters appear as one row, and only Pleiades was ever logged.

  2. Q30. Each log earns the points of its object. Show the watchers with at least 13 points, highest first. [4]
    Answer
    Query and resultthe full pattern
    SELECT Watcher, SUM(Points)
    FROM SKYLOG, SKYOBJ
    WHERE SKYLOG.Code = SKYOBJ.Code
    GROUP BY Watcher
    HAVING SUM(Points) >= 13
    ORDER BY SUM(Points) DESC;
    
    +---------------+-------------+
    | Watcher       | SUM(Points) |
    +---------------+-------------+
    | Tenzin Bhutia |          16 |
    | Zoya Khan     |          15 |
    | Aarush Nair   |          13 |
    +---------------+-------------+

    One mark each for the join, the grouping with SUM, HAVING, and the order. Check one by hand: Zoya logged M45, M42 and SAT, 4 + 6 + 5 = 15.

  3. Q31. Write the output. [2]
    Querypredict it
    SELECT UPPER(LEFT(OName, 4)), ROUND(Hours)
    FROM SKYLOG L, SKYOBJ O
    WHERE L.Code = O.Code AND Photos IS NULL;
    Answer
    Resultshort table names
    +-----------------------+--------------+
    | UPPER(LEFT(OName, 4)) | ROUND(Hours) |
    +-----------------------+--------------+
    | JUPI                  |            1 |
    | ANDR                  |            3 |
    +-----------------------+--------------+

    L and O are names given to the tables for this query. Two logs have NULL photos: log 3 on Jupiter, 0.85 rounded to 1, and log 6 on Andromeda, 2.65 rounded to 3.

  4. Q32. Hercules (M13) is in SKYOBJ. Why does it never appear in an equi-join with SKYLOG? [1]
    Answer No row of SKYLOG has the code M13, so the condition is never true for it. An equi-join keeps only the rows that match in both tables.

Q. Does Class 11 SQL come back?

Class 11 commands and NULL: the part of Class 12 IP SQL notes people skip

Yes. Unit 2 begins with revision of Class 11 SQL, and Question 37 of the 2026-27 sample paper gives five marks to INSERT, UPDATE, DELETE, ALTER and DROP as one of its two options.

One mark each

  1. Q33. Show the logs in which no photo count was entered.
    Answer
    Query and resultIS NULL
    SELECT LogNo, Watcher
    FROM SKYLOG
    WHERE Photos IS NULL;
    
    +-------+---------------+
    | LogNo | Watcher       |
    +-------+---------------+
    |     3 | Meera Das     |
    |     6 | Tenzin Bhutia |
    +-------+---------------+
  2. Q34. What does the same query return with WHERE Photos = NULL?
    Answer An empty set. Nothing is equal to NULL, not even another NULL. Use IS NULL or IS NOT NULL.
  3. Q35. Display watcher and hours for sessions from 1.25 to 1.75 hours, both included.
    Answer
    Query and resultBETWEEN
    SELECT Watcher, Hours
    FROM SKYLOG
    WHERE Hours BETWEEN 1.25 AND 1.75;
    
    +-------------+-------+
    | Watcher     | Hours |
    +-------------+-------+
    | Zoya Khan   |  1.75 |
    | Aarush Nair |  1.25 |
    | Meera Das   |  1.50 |
    +-------------+-------+

    BETWEEN includes both limits, so 1.25 and 1.75 are in the answer.

  4. Q36. Sort these into DDL and DML: UPDATE, ALTER, INSERT, DROP, DELETE, CREATE.
    Answer DDL, which changes structure: CREATE, ALTER, DROP. DML, which changes rows: INSERT, UPDATE, DELETE.

Two marks each

  1. Q37. Differentiate between DELETE and DROP, with an example of each.
    Answer DELETE removes rows and the table stays: DELETE FROM SKYOBJ WHERE Code = 'M13'; DROP removes the table itself, rows and structure: DROP TABLE SKYOBJ;
  2. Q38. Differentiate between ALTER and UPDATE, with an example of each.
    Answer ALTER changes the design, for example adds a column: ALTER TABLE SKYOBJ ADD Season VARCHAR(10); UPDATE changes the values in rows: UPDATE SKYOBJ SET Points = 7 WHERE Code = 'SAT';
  3. Q39. What is the difference between a single-row function and an aggregate function? Name one of each.
    Answer A single-row function returns a value for every row, for example LENGTH(). An aggregate function returns one value for a whole set of rows, for example SUM(). One mark for the difference, half for each name.

Five marks

  1. Q40. For the table SKYOBJ write commands to: (i) add a column Season of type VARCHAR(10); (ii) insert a new object MAR, Mars, Planet, 4 points, season Summer; (iii) raise the points of every Cluster by 2; (iv) remove the object with code JUP; (v) remove the table from the database.
    Answer
    Commandsone mark each
    ALTER TABLE SKYOBJ ADD Season VARCHAR(10);
    INSERT INTO SKYOBJ
    VALUES ('MAR', 'Mars', 'Planet', 4, 'Summer');
    UPDATE SKYOBJ SET Points = Points + 2
    WHERE Kind = 'Cluster';
    DELETE FROM SKYOBJ WHERE Code = 'JUP';
    DROP TABLE SKYOBJ;
    Resultafter (iv), before (v)
    +------+--------------+---------+--------+--------+
    | Code | OName        | Kind    | Points | Season |
    +------+--------------+---------+--------+--------+
    | M13  | Hercules     | Cluster |     10 | NULL   |
    | M31  | Andromeda    | Galaxy  |     10 | NULL   |
    | M42  | Orion Nebula | Nebula  |      6 | NULL   |
    | M45  | Pleiades     | Cluster |      6 | NULL   |
    | MAR  | Mars         | Planet  |      4 | Summer |
    | SAT  | Saturn       | Planet  |      5 | NULL   |
    +------+--------------+---------+--------+--------+

    The old rows show NULL under Season, because nothing was stored there. Without the WHERE in (iii) every object would have gained 2 points.

How the official scheme pays

Question in the 2026-27 SQPMarksHow the scheme splits them
26, two short queries21 for each
31, three queries on one table31 for each
32, three outputs, with a choice31 for each
34, two bigger queries or outputs, with a choice42 for each
37, five commands or five queries, with a choice51 for each

With one mark riding on a whole command, spelling a column the way the question spells it matters more than speed. For output questions the scheme prints column headings above the values, so write them too.

First the paper, then the prompt

In class a query is written by hand, read back as a sentence, and only then typed. The server is a referee, not a guesser.

Groups drawn with a pencil

Before running GROUP BY, the student circles the rows that belong together. A wrong count usually shows up here.

Seven more marks in the lab

SQL queries are 7 of the 30 practical marks. The same two-table habit serves both examinations.

Carry on with the 15 SQL queries of the IP practical file, the full IP practice paper, IP MCQs, or the important questions of all four units. If your subject is 083, the list is different: see Class 12 CS SQL questions.

One to one, at your own timing

Bring the query that gave the wrong rows

An SQL doubt is easiest to settle on a live table with one person watching. So Unit 2 is taught personalised one to one, on days and at hours you fix. You may begin with a priority demo, whose fee is adjusted in your first month if you enrol, or with a free demo class. Billing is monthly, admission costs nothing, and you can stop when any month ends.

Before you enrol · Try a class

Priority demo, at a slot you pick

a full live class of about 45 to 60 minutes

  • One query of each kind: function, grouping, join
  • You predict the grid before MySQL shows it
  • A four-mark answer is marked the way the scheme splits it
  • The skill report names the clauses that need work
Book a priority demo

The classes · Choose your own timing

Personalised one to one

₹4,999

per month, 4 private classes, fully flexible timing

  • Class 11 SQL repaired first if it is rusty
  • Your school's tables and worksheets used in class
  • Queries for your practical file understood, then written by you
  • Extra time on whichever of GROUP BY or join is weaker
Ask for a personalised plan

You will not be asked to learn queries by heart. The aim is that a new table in the exam looks like an old one with different names. Your fee is shown on this page in your own currency.

Studying outside India?

One to one IP SQL classes outside India

CBSE schools in the Gulf and elsewhere use the same 065 paper and the same function list. Pick an evening or a weekend morning where you live.

Where you liveTime differenceUsual class window, local timeFormat
India
every Indian city
Indian timeAny time you choosePersonalised 1-on-1
UAE and Oman
Dubai, Abu Dhabi, Sharjah, Muscat
1 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Saudi Arabia, Qatar, Kuwait, Bahrain
Riyadh, Jeddah, Dammam, Doha, Kuwait City, Manama
2 h 30 min behind India3:00 PM to 9:00 PMPersonalised 1-on-1
Nepal
Kathmandu
15 min ahead of India4:30 PM to 9:00 PMPersonalised 1-on-1
Ethiopia and East Africa
Addis Ababa and East Africa Time
2 h 30 min behind India4:30 PM to 9:00 PMPersonalised 1-on-1
Singapore and Malaysia
Singapore, Kuala Lumpur
2 h 30 min ahead of India3:30 PM to 9:00 PMPersonalised 1-on-1

If MySQL is not on your laptop yet, installing it can be the first thing we do together. Until then the class runs on the teacher's screen.

What families say

Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 12 series

More pages for Class 12 students

Every page in the CBSE Class 12 Informatics Practices series, grouped by what you need.

Questions about Unit 2

What students ask about SQL in Class 12 IP

How many marks is SQL in Class 12 IP?

Database Query using SQL is Unit 2 of CBSE Informatics Practices (065) and carries 25 of the 70 theory marks in 2026-27, the same as pandas with data visualization. In the sample paper these marks come from Questions 2, 6, 9, 11, 14, 17, 19, 21, 26, 31, 32, 34 and 37. SQL queries are also 7 of the 30 practical marks.

Which SQL functions are in the Class 12 IP syllabus?

Math: POWER, ROUND and MOD. Text: UCASE or UPPER, LCASE or LOWER, MID or SUBSTRING or SUBSTR, LENGTH, LEFT, RIGHT, INSTR, LTRIM, RTRIM and TRIM. Date: NOW, DATE, MONTH, MONTHNAME, YEAR, DAY and DAYNAME. Aggregate: MAX, MIN, AVG, SUM and COUNT, including COUNT(*). Nothing else is listed for 2026-27.

What is the difference between GROUP BY and ORDER BY?

GROUP BY puts rows with the same value together and returns one row for each group, normally with an aggregate function. ORDER BY only arranges the rows of the result and removes none of them. When both are used, GROUP BY comes first and ORDER BY is the last clause.

What is the difference between WHERE and HAVING in SQL?

WHERE tests single rows before they are grouped and cannot contain an aggregate function. HAVING tests groups after GROUP BY and usually contains one, for example HAVING COUNT(*) = 2. A query may have both: WHERE removes unwanted rows, then HAVING removes unwanted groups.

Are joins in the Class 12 IP syllabus?

Yes, but only one kind is named: working with two tables using equi-join. You write both tables after FROM and put the equality of the common column in WHERE. Natural join and outer joins are not listed in 065. Natural join belongs to the 083 Computer Science syllabus.

What is the difference between COUNT(*) and COUNT(column)?

COUNT(*) counts the rows, whatever they hold. COUNT(column) counts only the rows in which that column is not NULL. On a table of nine rows with two NULLs in Photos, COUNT(*) is 9 and COUNT(Photos) is 7. SUM and AVG also leave NULL out.

What is the difference between MID, SUBSTR and SUBSTRING?

None in MySQL. They are three names for one function, and the syllabus lists all three. Each takes the string, a starting position counted from 1, and how many characters to return. If the third value is missing, the rest of the string is returned.

Why does MONTH() give a number and MONTHNAME() a word?

They answer different questions. MONTH() returns 1 to 12, which is useful for comparing, as in WHERE MONTH(LDate) = 11. MONTHNAME() returns the full name, which is useful for display. DAY() and DAYNAME() differ in the same way: one gives the date of the month, the other the weekday.

Do I have to write column headings in output questions?

The official marking scheme for 2026-27 prints the headings with the values for table outputs, for example DAY(DOB) and YEAR(DOB). Copy the expression as it is in the SELECT line and write the values under it. It also helps you check that you have the right number of columns.

Is SQL case sensitive in the board exam?

Keywords and function names are not, so select and SELECT both work. Writing keywords in capitals makes the answer easier to read. Table and column names should be copied from the question. Text inside quotes is data, so copy it as the table shows it.

How can I practise Class 12 IP SQL at home?

Make two small tables of your own with about eight rows and a common column, and put one NULL in a number column. Write three queries a day: one with a function, one with GROUP BY, one equi-join. Predict the result on paper first. A wrong prediction teaches more than a right query.

Can I take one to one classes only for SQL?

Yes. Classes are live and personalised, so a student may work only on Unit 2 and stop after it. Times are chosen by you. Start with a priority demo, a full class of about 45 to 60 minutes with a written skill report, or with the free demo class. Billing is monthly.

Start

Write one query while we watch

The free demo class begins with a table and a question in plain English. You write the query, and the teacher shows you how MySQL reads it.

A priority demo is a complete class at the hour you pick. It goes through functions, grouping and a join, marks one answer fully, and ends with a written skill report. If you join, its fee is counted towards the first month.

Not sure where Unit 2 sits in your year? See the IP syllabus and paper pattern.

WhatsApp us · +91 91233 66161 · connect@modernagecoders.com

Every class is live video. The form requests a callback and reserves nothing.

We call within a few hours. No card, no enrolment fee.

Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

Book a priority demo

Keep exploring Modern Age Coders

By class and age

Learn more

Free resources

From the blog

Start here