Data Retrieval language(DRL)
Data Retrieval Language (DRL) is a part of SQL used to retrieve (fetch) data from a database without modifying it.
Main Command: SELECT – used to get data from one or more tables.
Examples:
|
1 2 3 4 5 |
SELECT * FROM students; → Retrieves all records from the students table. SELECT name, marks FROM students WHERE marks > 60; → Retrieves names and marks of students who scored more than 60. |
Purpose:
● To view data
● To filter required information
● To sort and display data in a useful format Marks-friendly line (for exams):
Data Retrieval Language (DRL) is used to retrieve data from a database. The SELECT command is used in DRL.
Distinct
DISTINCT is used in the SELECT statement to remove duplicate values and display unique records from a column.
Syntax:
|
1 2 3 |
SELECT DISTINCT column_name FROM table_name; Example: SELECT DISTINCT city FROM students; |
→ Displays each city only once, even if it appears many times in the table.
Use: To avoid repeated values & To get unique data
Exam answer (short): DISTINCT is used to retrieve unique values from a column by eliminating duplicate records.
Expression Definition:
An expression in SQL is a combination of columns, constants, operators, and functions that is used to calculate or derive a value.
Examples:
|
1 2 3 4 5 6 7 8 |
1. Arithmetic expression SELECT marks + 5 AS new_marks FROM students; 2. Comparison expression SELECT * FROM students WHERE marks > 60; 3. Logical expression SELECT * FROM students WHERE marks > 60 AND city = 'Pune'; |
Use: To perform calculations, To compare values & To filter data
Exam-friendly line:
An expression in SQL is a formula used to compute or evaluate values using operators and operands.
Definition:An alias is a temporary name given to a column or a table to make the output easy to read. It does not change the original name.
Syntax:
SELECT column_name AS alias_name FROM table_name; (or AS is optional)
Examples:
|
1 2 3 4 5 |
1. Column alias SELECT name AS student_name FROM students; 2. Table alias SELECT s.name FROM students s; |
Use:
● To improve readability To shorten long names
● Useful in expressions and joins
Exam-friendly line: Alias names are temporary names given to columns or tables using AS for easy identification.
Operators
Definition: Operators are symbols used to perform operations on data in SQL expressions and conditions.
Types of SQL Operators:
Arithmetic Operators
+ , − , * , / , %
Example: SELECT marks + 10 FROM students;
Comparison (Relational) Operators
= , != , > , < , >= , <=
Example: SELECT * FROM students WHERE marks >= 60;
Logical Operators AND , OR , NOT
Example: SELECT * FROM students WHERE marks > 60 AND city = ‘Mumbai’;
Special Operators
IN , BETWEEN , LIKE , IS NULL
Example: SELECT * FROM students WHERE city IN (‘Pune’,’Delhi’); There are three types of operaters
Arithmetic operators
Arithmetic operators are used in SQL to perform mathematical calculations on numeric data. Types of Arithmetic Operators
| Operator | Name | Description | Example |
| + | Addition | Adds two values | marks + 5 |
| – | Subtraction | Subtracts one value from another | marks – 10 |
| * | Multiplication | Multiplies values | marks * 2 |
| / | Division | Divides one value by another salary | marks / 2 |
| % | Modulus | Returns remainder after division | marks % 2 |
Examples with Explanation
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<strong>Addition </strong>SELECT marks + 5 AS updated_marks FROM students; → Adds 5 to each student’s marks. <strong>Subtraction </strong>SELECT marks - 3 FROM students; → Subtracts 3 from marks. <strong>Multiplication </strong>SELECT quantity * price AS total_cost FROM sales; → Calculates total cost. <strong>Division </strong>SELECT salary / 12 AS monthly_salary FROM employee; → Converts yearly salary into monthly salary. <strong>Modulus </strong>SELECT marks % 2 FROM students; → Shows remainder (useful to check even/odd). Uses of Arithmetic Operators |
To calculate totals, averages, discounts To modify numeric values in queries Used in SELECT, WHERE, and UPDATE
*Arithmetic operators in SQL are used to perform mathematical calculations on numeric data. They include +, −, , /, and %. These operators are commonly used in expressions to calculate totals, differences, and other numeric results.
Relational (Comparison) Operators
Relational operators are used in SQL to compare two values. They return TRUE or FALSE and are mainly used in the WHERE clause.
| Operator | Description | Example |
| = | Equal to | marks = 60 |
| != or <>. | Not equal to | marks != 50 |
| > | Greater than | marks > 60 |
| < | Less than. | marks < 40 |
| >= | Greater than Or equal to. | marks >= 75 |
| <= | Less than or equal to | marks <= 35 |
Examples with Explanation
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Equal to SELECT * FROM students WHERE city = 'Pune'; → Selects students from Pune. Greater than SELECT * FROM students WHERE marks > 60; → Selects students scoring above 60. Less than or equal to SELECT * FROM students WHERE age <= 18; → Selects students aged 18 or below. |
Uses
● To filter records
● To apply conditions
● Used with WHERE, HAVING
> Relational operators are used to compare values in SQL. They include =, !=, >, <, >= and
<= and help in filtering records based on conditions.
Logical Operators
Logical operators are used to combine multiple conditions in a SQL query. They return TRUE or FALSE.
Types of Logical Operators
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<strong>AND </strong>Returns TRUE when all conditions are true. SELECT * FROM students WHERE marks > 60 AND city = 'Pune'; <strong>OR </strong>Returns TRUE when any one condition is true. SELECT * FROM students WHERE marks > 60 OR city = 'Mumbai'; <strong>NOT </strong>Reverses the condition. SELECT * FROM students WHERE NOT city = 'Delhi'; |
Uses
To apply multiple conditions To filter data accurately
Used mainly in WHERE and Having
> Logical operators in SQL are used to combine conditions. AND, OR, and NOT are the logical operators that help in decision making.
Author : Lavanya Nandairi
LinkedIn : https://www.linkedin.com/in/lavanya-nandagiri-817194375/
Thank you for giving your valuable time to read the above information. Please click here to subscribe for further updates.
KTExperts is always active on social media platforms.
Facebook : https://www.facebook.com/ktexperts
LinkedIn : https://www.linkedin.com/company/ktexperts/
Twitter : https://twitter.com/ktexpertsadmin
YouTube : https://www.youtube.com/c/ktexperts
Instagram : https://www.instagram.com/knowledgesharingplatform
Note: Please test scripts in Non Prod before trying in Production.




