Informatics Practices

DQL Commands in MySQL | SELECT, FROM and WHERE Clause | Complete Notes | CBSE Class 11 Informatics Practices (2026–27)

Class 11 · Informatics Practices

DQL Commands in MySQL | SELECT, FROM and WHERE Clause

After creating a database and storing data using DML commands, the next step is to retrieve the required information. This is done using Data Query Language (DQL). The most important DQL command is the SELECT statement, which is used to display records from one or more tables.

The FROM clause specifies the table from which data is retrieved, while the WHERE clause filters records based on a given condition. These commands form the foundation of SQL queries and are extensively used in database applications.


Learning Outcomes

After studying this chapter, you will be able to:

  • Understand the purpose of DQL commands.
  • Retrieve records using the SELECT statement.
  • Display specific columns from a table.
  • Use the FROM clause correctly.
  • Filter records using the WHERE clause.
  • Understand relational operators used in SQL.

What is DQL?

Definition

Data Query Language (DQL) is a category of SQL commands used to retrieve data from one or more database tables. The primary DQL command is SELECT.


The SELECT Statement

Definition

The SELECT statement is used to retrieve data from a database table.


Syntax


SELECT column_name
FROM table_name;

Example


SELECT Name
FROM Student;

This query displays the values stored in the Name column.


Sample Student Table

Roll_No Name Class Marks
101 Aarav XI 91.5
102 Diya XI 88.0
103 Kabir XI 94.0
104 Riya XII 96.5

Selecting All Columns

The asterisk (*) symbol is used to display all columns of a table.

Syntax


SELECT *
FROM table_name;

Example


SELECT *
FROM Student;

The above query displays every column and every record from the Student table.


Selecting Specific Columns

If only certain columns are required, mention their names separated by commas.

Syntax


SELECT column1, column2
FROM table_name;

Example


SELECT Roll_No, Name
FROM Student;

This query displays only the Roll_No and Name columns.


The FROM Clause

Definition

The FROM clause specifies the table from which data will be retrieved.

Example


SELECT Name
FROM Student;

Here, Student is the table from which data is fetched.


Why Use the WHERE Clause?

In many situations, users do not need all the records. They may want only those records that satisfy a particular condition. The WHERE clause is used for this purpose.

Definition

The WHERE clause filters records according to a specified condition.


Syntax


SELECT column_name
FROM table_name
WHERE condition;

Example


SELECT *
FROM Student
WHERE Class = 'XI';

The above query displays only those students who belong to Class XI.


Result of the Above Query

Roll_No Name Class Marks
101 Aarav XI 91.5
102 Diya XI 88.0
103 Kabir XI 94.0


Relational Operators in SQL

Relational operators are used with the WHERE clause to compare values and retrieve only those records that satisfy a given condition.

Operator Meaning Example
= Equal to Marks = 90
> Greater than Marks > 90
< Less than Marks < 90
>= Greater than or equal to Marks >= 80
<= Less than or equal to Marks <= 80
<> or != Not equal to Class <> 'XI'

Examples Using Relational Operators

Example 1: Equal To (=)


SELECT *
FROM Student
WHERE Roll_No = 102;

Displays the record of the student whose Roll Number is 102.


Example 2: Greater Than (>)


SELECT Name, Marks
FROM Student
WHERE Marks > 90;

Displays the names and marks of students scoring more than 90.


Example 3: Less Than (<)


SELECT *
FROM Student
WHERE Marks < 90;

Displays students whose marks are less than 90.


Example 4: Greater Than or Equal To (>=)


SELECT Name
FROM Student
WHERE Marks >= 95;

Displays students who scored 95 or more marks.


Example 5: Less Than or Equal To (<=)


SELECT *
FROM Student
WHERE Marks <= 88;

Displays students having marks less than or equal to 88.


Example 6: Not Equal To (<>)


SELECT *
FROM Student
WHERE Class <> 'XI';

Displays students who do not belong to Class XI.


Comparison of SELECT Queries

Query Purpose
SELECT * FROM Student; Displays all records and all columns.
SELECT Name FROM Student; Displays only the Name column.
SELECT Roll_No, Name FROM Student; Displays selected columns.
SELECT * FROM Student WHERE Class='XI'; Displays students of Class XI.
SELECT Name FROM Student WHERE Marks > 90; Displays names of students scoring above 90.

Solved Example 1

Display all records from the Student table.

Solution:


SELECT *
FROM Student;

Solved Example 2

Display only the Roll Number and Name of all students.

Solution:


SELECT Roll_No, Name
FROM Student;

Solved Example 3

Display the records of students belonging to Class XII.

Solution:


SELECT *
FROM Student
WHERE Class = 'XII';

Solved Example 4

Display the names of students who scored more than 90 marks.

Solution:


SELECT Name
FROM Student
WHERE Marks > 90;

Solved Example 5

Display the details of students whose marks are less than or equal to 88.

Solution:


SELECT *
FROM Student
WHERE Marks <= 88;

Common Errors

Mistake Correct Practice
Forgetting the FROM clause. Always specify the table name after FROM.
Using incorrect column names. Column names must exactly match the table structure.
Writing text values without single quotes. Enclose text values within single quotes.
Using the wrong relational operator. Select the operator based on the required condition.
Forgetting the semicolon (;). Terminate every SQL statement with a semicolon.

Interview Corner

Q. What is the difference between SELECT * and SELECT Name?

Answer: SELECT * displays all columns of a table, whereas SELECT Name displays only the Name column.



Real-Life Applications of DQL Commands

Organization SQL Query Purpose
School SELECT * FROM Student; Display all student records.
School SELECT Name FROM Student WHERE Class='XI'; Display names of students studying in Class XI.
Bank SELECT * FROM Customer WHERE Balance > 50000; Find customers with a balance greater than 50,000.
Hospital SELECT Name FROM Patient WHERE Blood_Group='O+'; Find patients having O+ blood group.
Library SELECT * FROM Book WHERE Price < 500; Display books priced below ₹500.
Online Shopping SELECT Product_Name FROM Product WHERE Stock > 0; Display products currently available.

Solved Example 6

Display the names and marks of all students.

Solution:


SELECT Name, Marks
FROM Student;

Solved Example 7

Display all students whose marks are greater than or equal to 90.

Solution:


SELECT *
FROM Student
WHERE Marks >= 90;

Solved Example 8

Display the Roll Number and Name of students whose class is XI.

Solution:


SELECT Roll_No, Name
FROM Student
WHERE Class = 'XI';

Solved Example 9

Display all students except those studying in Class XII.

Solution:


SELECT *
FROM Student
WHERE Class <> 'XII';

Solved Example 10

Display the names of students who scored less than 90 marks.

Solution:


SELECT Name
FROM Student
WHERE Marks < 90;

Competency-Based Questions

  1. A school wants to display the names of students who belong to Class XII. Write the SQL query.
  2. Write an SQL query to display the Roll Number and Name of students whose marks are greater than 85.
  3. A library wants to display details of books costing less than ₹300. Write the SQL query.
  4. Differentiate between the SELECT * statement and selecting specific columns with suitable examples.
  5. Explain the purpose of the WHERE clause. Why is it important while retrieving data?

Multiple Choice Questions

  1. DQL stands for:
    • (a) Data Question Language
    • (b) Data Query Language
    • (c) Database Query Logic
    • (d) Data Quality Language
  2. Which SQL command is used to retrieve records from a table?
    • (a) INSERT
    • (b) UPDATE
    • (c) SELECT
    • (d) DELETE
  3. The FROM clause specifies:
    • (a) Column name
    • (b) Table name
    • (c) Data type
    • (d) Database name
  4. Which clause filters records based on a condition?
    • (a) ORDER BY
    • (b) GROUP BY
    • (c) WHERE
    • (d) VALUES
  5. Which operator checks whether two values are equal?
    • (a) >
    • (b) =
    • (c) <>
    • (d) >=
  6. Which query displays all columns of the Student table?
    • (a) SELECT Student;
    • (b) SELECT * FROM Student;
    • (c) SELECT ALL Student;
    • (d) SHOW Student;
  7. Which operator is used for "Not Equal To"?
    • (a) =
    • (b) >
    • (c) <>
    • (d) <=
  8. Which query displays only the Name column?
    • (a) SELECT * FROM Student;
    • (b) SELECT Name FROM Student;
    • (c) SHOW Name;
    • (d) DISPLAY Name;
  9. Which SQL statement displays students whose marks are greater than 80?
    • (a) SELECT * FROM Student WHERE Marks < 80;
    • (b) SELECT * FROM Student WHERE Marks > 80;
    • (c) SELECT Marks = 80;
    • (d) SELECT Student > 80;
  10. Which of the following is a DQL command?
    • (a) INSERT
    • (b) UPDATE
    • (c) DELETE
    • (d) SELECT

Quick Revision

Statement / Clause Purpose
SELECT Retrieves data from a table.
FROM Specifies the table name.
WHERE Filters records based on conditions.
* Selects all columns.
= Equal to
> Greater than
< Less than
<> Not equal to

Important Points to Remember

  • DQL is mainly used for retrieving data from database tables.
  • The SELECT statement is the primary DQL command.
  • The FROM clause specifies the table from which data is retrieved.
  • The WHERE clause filters records based on specified conditions.
  • The asterisk (*) retrieves all columns from a table.
  • Use commas to retrieve multiple specific columns.
  • Text values in the WHERE clause should be enclosed within single quotes.
  • Relational operators help compare values while filtering records.
  • Every SQL statement should end with a semicolon (;).

CBSE Exam Tips

  • Memorize the syntax of SELECT, FROM, and WHERE statements.
  • Practice writing SQL queries using different relational operators.
  • Understand the difference between SELECT * and selecting specific columns.
  • Be able to identify the correct SQL query for competency-based questions.
  • Read the condition carefully before choosing the appropriate relational operator.

Summary

Data Query Language (DQL) is used to retrieve information from database tables. The SELECT statement displays data, the FROM clause specifies the table, and the WHERE clause filters records based on conditions. Relational operators such as =, >, <, >=, <=, and <> make it possible to retrieve only the required records. Mastering these commands is essential for writing efficient SQL queries and forms the foundation for advanced SQL concepts.