CBSE • Class 12 • Informatics Practices
Database Query Using SQL
SQL queries, database operations, joins, grouping, functions and data retrieval.
Chapter 2
Verified Curriculum Topic
What is Database Query Using SQL?
SQL queries, database operations, joins, grouping, functions and data retrieval.
Database Query Using SQL matters because it is one of the building blocks of informatics practices at Class 12 level. Students are usually expected to understand the key idea, use the correct vocabulary, and explain or apply the concept in a clear academic way.
Study Database Query Using SQL now
Summary
Main Idea
SQL is used to create, retrieve, modify, and manage data stored in relational databases. Its queries combine commands, conditions, operators, functions, grouping, sorting, and joins to obtain meaningful information, while aggregate functions support the summarisation of data for analysis and reporting.
Key Concepts and Definitions
- Database: An organized collection of related data stored for easy access and management.
- Table: A structure in a relational database that stores data in rows and columns.
- Record or Row: A complete set of related values representing one entity or item in a table.
- Field or Column: A named attribute that stores one type of information for all records.
- Primary Key: A column or combination of columns that uniquely identifies each row in a table.
- Foreign Key: A column that refers to the primary key of another table and establishes a relationship between tables.
- SQL: Structured Query Language used to communicate with and manage relational databases.
- DDL: Data Definition Language commands such as
CREATE,ALTER, andDROPused to define database structures. - DML: Data Manipulation Language commands such as
INSERT,UPDATE, andDELETEused to change table data. - DQL: Data Query Language, mainly represented by
SELECT, used to retrieve data. - SELECT: Retrieves specified columns or expressions from one or more tables.
- FROM: Specifies the table or tables from which data is selected.
- WHERE: Filters individual rows according to a condition.
- DISTINCT: Removes duplicate values from the query result.
- ORDER BY: Sorts query results in ascending (
ASC) or descending (DESC) order. - Aliases: Temporary alternative names given to tables or columns using
AS. - Operators: Symbols or keywords used in conditions, including arithmetic, comparison, logical,
IN,BETWEEN,LIKE, andIS NULLoperators. - NULL: A special value indicating missing, unknown, or unavailable data; it is tested using
IS NULLorIS NOT NULL. - Aggregate Function: A function that processes multiple rows and returns one result, such as
COUNT,SUM,AVG,MIN, andMAX. - Scalar Function: A function that works on individual values and returns one result for each row, such as
UCASE,LCASE,LENGTH,ROUND, andMOD. - GROUP BY: Combines rows having the same values in selected columns so that aggregate calculations can be performed for each group.
- HAVING: Filters groups after
GROUP BY, usually using aggregate conditions. - Join: A query operation that combines rows from related tables using matching columns.
- Equi-Join: A join that matches rows using equality between related columns, commonly written with
INNER JOINor aWHEREcondition. - Cartesian Product: The result of combining every row of one table with every row of another table, usually produced by a join without a matching condition.
- Constraint: A rule applied to table data, such as
PRIMARY KEY,NOT NULL,UNIQUE,DEFAULT, andCHECK.
Supporting Arguments and Evidence
- Basic retrieval uses
SELECTwithFROM:
SELECT column1, column2 FROM table_name;
To retrieve every column, use:
SELECT * FROM table_name;
A query should select only the required columns when possible because this improves clarity and can reduce unnecessary data retrieval.- The
WHEREclause filters individual rows:
SELECT columns FROM table_name WHERE condition;
Common comparison operators are =, <>, !=, <, >, <=, and >=. Logical operators AND, OR, and NOT combine or reverse conditions.- SQL provides specialised filtering operators.
INtests membership in a list:
WHERE city IN ('Delhi', 'Mumbai')
BETWEEN checks an inclusive range:
WHERE marks BETWEEN 60 AND 90
LIKE performs pattern matching: % represents any number of characters, while _ represents one character.NULLrepresents missing, unknown, or unavailable information. It must be tested withIS NULLorIS NOT NULL; ordinary comparison operators do not correctly testNULL.
- Results can be sorted using:
SELECT columns FROM table_name
ORDER BY column_name ASC;
or:
SELECT columns FROM table_name
ORDER BY column_name DESC;
DISTINCT removes duplicate values, and aliases provide temporary alternative names using AS.- Aggregate functions summarise multiple rows. These include
COUNT(),SUM(),AVG(),MIN(), andMAX().COUNT(*)counts rows, whereasCOUNT(column)ignoresNULLvalues in that column.
- Grouped summaries use:
SELECT group_column, aggregate_function(column)
FROM table_name
GROUP BY group_column;
GROUP BY forms groups with the same values, while HAVING filters those groups. In contrast, WHERE filters individual rows before grouping.- A common logical processing order is:
FROM and JOIN, WHERE, GROUP BY, HAVING, SELECT, and ORDER BY.
Understanding this order helps explain why WHERE applies to rows and HAVING applies to groups.- Joins combine related data from multiple tables. A standard inner join is:
SELECT columns
FROM table1
INNER JOIN table2
ON table1.common_column = table2.common_column;
An INNER JOIN returns only rows with matching values in both tables. A LEFT JOIN returns all rows from the left table and matching rows from the right table; where no match exists, right-side values appear as NULL.- An equi-join matches related columns using equality, either through
INNER JOINor an equivalentWHEREcondition. Joins without a matching condition can produce a Cartesian product, combining every row of one table with every row of another table. Therefore, joins should use clearly related tables and appropriate matching conditions.
- SQL also modifies and defines database structures. The relevant statements are:
INSERT INTO table_name (column1, column2)
VALUES (value1, value2);
UPDATE table_name
SET column1 = value1
WHERE condition;
DELETE FROM table_name
WHERE condition;
A WHERE clause should generally be used with UPDATE to avoid changing every row and with DELETE to avoid deleting every row. Without WHERE, all rows may be affected or deleted.CREATE TABLEdefines a table, including its columns, data types, and constraints.ALTER TABLEchanges an existing structure, such as by adding or modifying a column.DROP TABLEpermanently removes a table and its stored data.
- Common MySQL data types include
INTfor whole numbers,DECIMALfor precise numeric values,CHARorVARCHARfor text,DATEfor dates, andTIMEfor time values. String and date values are generally written inside single quotation marks. SQL keywords are commonly written in uppercase for readability, although many systems accept lowercase keywords, and a semicolon usually marks the end of an SQL statement.
- SQL functions can transform data during retrieval without changing the original stored values. Scalar function examples include:
UCASE(text)
- LCASE(text)
- LENGTH(text)
- LEFT(text, number)
- RIGHT(text, number)
- ROUND(number, decimals)
- MOD(number, divisor) Date-related functions may include YEAR(date), MONTH(date), DAY(date), NOW(), and CURDATE(), depending on the SQL system.
- Primary keys maintain uniqueness, while foreign keys establish relationships between tables. Together with constraints such as
PRIMARY KEY,NOT NULL,UNIQUE,DEFAULT, andCHECK, they support the integrity and reliable management of relational data.
What to Remember
SQL uses SELECT, FROM, WHERE, and ORDER BY to retrieve, filter, and arrange data; aggregate functions with GROUP BY and HAVING summarise it. Joins combine related tables through matching columns, whereas missing join conditions can create a Cartesian product. Primary and foreign keys maintain database relationships, and suitable WHERE conditions are essential when using UPDATE and DELETE to prevent unintended changes.
Flashcards
Quick quiz
Which SQL command is primarily used to retrieve data from a relational database?
Save this & unlock the full study pack
Create a free account to save Database Query Using SQL, get the complete set of notes, flashcards, quizzes, mind maps, and mock exams, and track your progress across Informatics Practices.
Sign up free — save & unlock everythingKey ideas to master
- Write a short, accurate explanation of Database Query Using SQL from memory.
- List the essential definitions, principles, or subtopics that belong to this chapter.
- Practise applying the idea to examples instead of only rereading notes.
- Review common confusions and turn them into flashcards or quick quiz questions.
Common exam prompts
- Define Database Query Using SQL in one clear academic paragraph.
- List the key points a student should remember before an exam on this topic.
- Explain how Database Query Using SQL connects to the wider informatics practices syllabus.
- Turn the chapter into a quick self-test with short-answer and recall questions.
How to study Database Query Using SQL effectively
Step 1
Start with a clear summary
Generate a concise summary first so you can see the core idea, the main vocabulary, and the chapter structure before going deeper.
Step 2
Turn it into active recall
Use flashcards and a short quiz to test whether you can reproduce the ideas in your own words instead of only recognising them.
Step 3
Ask the tutor where you are weak
Use AI Tutor for step-by-step explanations, simpler language, and one-question checks whenever part of the chapter still feels unclear.
Quick answers students usually need
What is Database Query Using SQL in CBSE Class 12 Informatics Practices?
SQL queries, database operations, joins, grouping, functions and data retrieval.
How should I study Database Query Using SQL effectively?
Start with a concise summary, then move into notes, flashcards, and a short quiz. Use AI Tutor when you need a simpler explanation, a worked example, or a quick oral check on the part that still feels unclear.
What can Study Buddy generate for Database Query Using SQL?
From this verified topic path, Study Buddy can generate summaries, detailed notes, flashcards, quizzes, mind maps, and follow-up tutor explanations that stay aligned with the selected curriculum branch.
Generate Your Study Pack
Get AI-generated notes, flashcards, quizzes, and mind maps for Database Query Using SQL. All content is curriculum-aligned and tailored to Class 12 level.
More Topics in Informatics Practices
Pandas, data frames, series, importing data, data analysis and visualization with Matplotlib.
Network concepts, devices, protocols, internet, web services and network safety.
Digital footprint, cyber safety, data protection, intellectual property and social impacts of technology.
Useful next links for this topic
Back to all Informatics Practices topics
Compare this chapter with the rest of the subject and open the next verified topic path directly.
Browse the full Class 12 library
Jump back to the grade hub if you need to switch subjects or revise another chapter next.
AI study strategy guide
See the best overall way to study more actively with AI help.
AI exam prep workflow
Move from raw notes into a more structured revision plan.