Informatics Practices · Class 12 Optional
Ch 1Querying and SQL Functions — Class 12 Informatics Practices, concept-first.
In Class XI, you learned the fundamentals of databases — how to create them in MySQL, populate them with data, and retrieve that data using SQL queries. This chapter builds directly on that foundation.
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
SQL Rounding Functions
Imagine you're keeping a record of your monthly expenses. You spend ₹1,247.83 on groceries, ₹532.19 on transport, and ₹2,108.56 on rent.
Most relevant Q&A
- In order to increase sales, a car dealer decides to offer customers the option to pay the total amount in 10 easy EMIs (equal monthly instal…Preview
- Using the table SALE of CARSHOWROOM database, write SQL queries for the following: (a) Display the InvoiceNo and commission value rounded of…Preview
- Using the SALE table of the CARSHOWROOM database: (a) Add a new column Commission to the SALE table. The column Commission should have a tot…Preview
- Using the table EMPLOYEE of CARSHOWROOM database, list the day of birth for all employees whose salary is more than 25000.Preview
- (a) Find sum of Sale Price of the cars purchased by the customer having ID C0001 from table SALE. (b) Find the maximum and minimum commissio…Preview
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Introduction
In Class XI, you learned the fundamentals of databases — how to create them in MySQL, populate them with data, and retrieve that data using SQL queries.
Functions in SQL
Functions are a core part of SQL, just as they are in programming languages. A function takes some input, performs a specific task, and returns a result.
Single Row Functions
Single row functions are also known as scalar functions. They are applied on a single value and return a single value — one output for every row they process.
Numeric Functions
3 QNumeric (math) functions take numbers in and give numbers out. The textbook works with three commonly used ones — POWER(), ROUND() and MOD() — whose syntax and worked outputs are listed in Table 1.5:
+−Worked Examples1 question
+−Worked Examples1 question
String Functions
3 QString functions perform operations on alphanumeric data — changing case, extracting a substring, measuring length, locating one string inside another, and stripping unwanted spaces.
+−Worked Examples1 question
+−Activities1 question
Date and Time Functions
3 QDate and time functions operate on date and time data — displaying the current date, extracting a date's day/month/year, or naming the day of the week.
+−Worked Examples1 question
+−Activities1 question
+−Think & Reflect1 question
Aggregate Functions
2 QAggregate functions are also called multiple-row functions. Unlike single-row functions that work on one row at a time, aggregate functions work on a whole set of records at once.
+−Worked Examples1 question
GROUP BY in SQL
2 QThe whole point of GROUP BY is to stop treating your table as a list of individual rows and start treating it as a collection of groups.
+−Worked Examples1 question
Operations on Relations
Operations on relations let us combine or compare data from two tables. The textbook introduces three such operations: Union, Intersection, and Set Difference.
Union (U)
The Union operation combines the selected rows from two tables into a single result. If a row appears in both tables, it is shown only once in the output — duplicates are automatically removed.
Intersect (∩)
The INTERSECT operation, denoted by the symbol ∩, is used to find common tuples (rows) that appear in two tables.
Minus (-)
The MINUS operation, written with the minus sign (−), answers a simple question: Which rows exist in the first table but not in the second? It is also called set difference.
Cartesian Product
The Cartesian product is a set operation that combines every row from one relation with every row from another relation.
Using Two Relations in a Query
We have so far written every query using only one table — a single relation. But real databases store related data across multiple tables.
Cartesian Product on Two Tables
The Cartesian product is the operation that underlies every query involving more than one table. When you list multiple tables in the FROM clause separated by commas, the database engine first combine…
Join on Two Tables
A database is rarely useful if you can only look at one table at a time. Real questions — like "What is the price of a white shirt?" — require data from two different tables.
Summary
- A Function is used to perform a particular task and return a value as a result. - Single row functions work on a single row to return a single value.
Exercises
+−Show 5 questionsHide questions5 questions
- Q1Answer the following questions: (a) Define RDBMS. Name any two RDBMS software. (b) What is the purpose of the following clauses in a SELECT…Free
- Q2Write the output produced by the following SQL commands: (a) SELECT POW(2,3); (b) SELECT ROUND(123.2345, 2), ROUND(342.9234, -1); (c) SELECT…Free
- Q3Consider the following table named "Product", showing details of products being sold in a grocery shop. | PCode | PName | UPrice | Manufactu…Preview
- Q4Using the CARSHOWROOM database given in the chapter, write the SQL queries for the following: (a) Add a new column Discount in the INVENTORY…Preview
- Q5Consider the following tables Student and Stream in the Streams_of_Students database. The primary key of the Stream table is StCode (stream…Preview
Sample & Board Papers
Sample papers and previous-year board questions for this subject.
+−Show 20 questionsHide questions20 questions
- Q1Which MySQL command helps to add a primary key constraint to any table that has already been created ? (A) UPDATE (B) INSERT INTO (C) ALTER…Preview
- Q2Which of the following clause cannot work with SELECT statement in MYSQL ? (A) FROM (B) INSERT INTO (C) WHERE (D) GROUP BYPreview
- Q3Write any two differences between UPDATE and ALTER TABLE commands of MySQL.Preview
- Q4Rupam created a MySQL table to store the details of Nobel prize winners. Help her to write the following MySQL queries : TABLE : NOBEL | Win…Preview
- Q5State whether the following statement is True or False : In SQL, an aggregate function returns multiple values for each column on which it i…Preview
- Q6Which of the following is the correct expanded form of DML ? (A) Device Management Language (B) Device Manipulation Language (C) Data Manage…Preview
- Q7State whether the following statement is True or False : The INSTR(string1, string2) function in SQL returns 0 if string2 is not present as…Preview
- Q8Q. 20 and Q. 21 are Assertion (A) and Reason (R) Type questions. Choose the correct option as : (A) Both (A) and (R) are True, and (R) corre…Preview
- Q9Define the following terms with respect to RDBMS : a. Domain b. TuplePreview
- Q10To remove the leading and trailing space from data values in a column of MySql Table, we use (A) Left ( ) (B) Right ( ) (C) Trim ( ) (D) Ltr…Preview
- Q11If the substring is not present in a string, the INSTR ( ) returns: (A) - 1 (B) 1 (C) NULL (D) 0Preview
- Q12Keshav has written the following query to find out the sum of bonus earned by the employees of WEST zone: SELECT zone, TOTAL (bonus) FROM em…Preview
- Q13Differentiate between COUNT ( ) and COURT (*) functions in MYSQL. Give suitable examples to support your answer.Preview
- Q14State whether the following statement is True or False: The MOD() function in SQL returns the quotient of division operation between two num…Preview
- Q15What is a Database Management System (DBMS)? Mention any two examples of DBMS.Preview
- Q16In CHAR(10) and VARCHAR(10), what does the number 10 indicate ?Preview
- Q17‘Employee’ table has a column named ‘CITY’ that stores city in which each employee resides. Write SQL query to display details of all rows e…Preview
- Q18Write SQL statement to add a column “COUNTRY” with data type and size as VARCHAR(70) to the existing table named “PLAYER”. Is it a DDL or DM…Preview
- Q19Consider the following table ‘Transporter’ that stores the order details about items to be transported. Table : TRANSPORTER | ORDERNO | DRIV…Preview
- Q20Consider the following tables PARTICIPANT and ACTIVITY and answer the questions that follow : Table : PARTICIPANT | ADMNO | NAME | HOUSE | A…Preview