Difference between revisions of "PostgreSQL-Database/C2/Conditional-Operators/English"
(Created page with "'''Title of the script: Conditional Operators''' '''Authors: '''Ketki Bhamble EduPyramids '''Keywords: '''PostgreSQL, pgAdmin 4, SQL, WHERE Clause, LIKE, percent sign, un...") |
|||
| Line 1: | Line 1: | ||
'''Title of the script: Conditional Operators''' | '''Title of the script: Conditional Operators''' | ||
| − | |||
'''Authors: '''Ketki Bhamble EduPyramids | '''Authors: '''Ketki Bhamble EduPyramids | ||
| − | |||
'''Keywords: '''PostgreSQL, pgAdmin 4, SQL, WHERE Clause, LIKE, percent sign, underscore, BETWEEN, NOT BETWEEN, IN, NOT IN, DISTINCT, EduPyramids, video tutorial. | '''Keywords: '''PostgreSQL, pgAdmin 4, SQL, WHERE Clause, LIKE, percent sign, underscore, BETWEEN, NOT BETWEEN, IN, NOT IN, DISTINCT, EduPyramids, video tutorial. | ||
| − | |||
Latest revision as of 12:14, 24 April 2026
Title of the script: Conditional Operators
Authors: Ketki Bhamble EduPyramids
Keywords: PostgreSQL, pgAdmin 4, SQL, WHERE Clause, LIKE, percent sign, underscore, BETWEEN, NOT BETWEEN, IN, NOT IN, DISTINCT, EduPyramids, video tutorial.
| Visual Cue | Narration |
| Slide 1
|
Welcome to this Spoken Tutorial on Conditional Operators in PostgreSQL. |
| Slide 2
|
In this tutorial, we will learn about,
|
| Slide 3
|
To record this tutorial, I am using the following setup. |
| Slide 4
|
To follow this tutorial,
|
| Slide 5
This file is provided in the Code Files link on this tutorial page. |
The following code file is required to practice this tutorial.
|
| Let us get started. | |
| Show students-table | We are using the students table.
|
| Slide 6
|
The LIKE operator is used to search for a specified pattern in a column.
It is used along with the WHERE clause.
|
| Slide 7
FROM table_name WHERE columnN LIKE pattern;
|
This is the syntax of the LIKE operator.
The pattern may contain percent sign or underscore.
Underscore represents exactly one character. |
| Type the command:
WHERE studentname LIKE 'R%';
|
Let us retrieve the records of students whose names start with the letter R.
|
| Type the query:
FROM students WHERE city LIKE '%a'; |
Now let’s find students whose city name ends with letter a using the WHERE clause.
|
| Highlight LIKE '%a' | This query retrieves studentname and city.
The pattern '%a' means any number of characters followed by the letter a. |
| Click the Execute query icon. | Let us execute the query.
|
| Slide 8
|
The BETWEEN operator is used to filter values within a specified range.
|
| Slide 9
FROM table name WHERE column name BETWEEN value1 AND value2; |
This is the syntax of BETWEEN operator. |
| Type the command:
SELECT studentname, cgpa FROM students WHERE cgpa BETWEEN 8 AND 9; |
Let us now find students whose CGPA is between 8 and 9.
|
| Highlight BETWEEN 8 AND 9 | This query retrieves the studentname and c g p a.
It includes values greater than or equal to 8 and less than or equal to 9. |
| Click the Execute query icon. | Let us execute the query.
|
| Type the command:
SELECT studentname, dob FROM students WHERE dob BETWEEN '1996-01-01' AND '1996-12-31';
|
Now, let us find students born in the year 1996.
|
| Click the Execute query icon. | Let us execute the query.
The output displays students born in the year 1996. |
| Slide 10
|
The NOT BETWEEN operator is used to filter values that fall outside a specified range. |
| Slide 11
FROM table name WHERE column name NOT BETWEEN value1 AND value2; |
This is the syntax of the NOT BETWEEN operator. |
| Type:
FROM students WHERE cgpa NOT BETWEEN 8 AND 9; |
Let us retrieve students whose CGPA is not between 8 and 9.Type this query. |
| Highlight NOT BETWEEN 8 AND 9 | The NOT BETWEEN clause returns rows where cgpa is less than 8 or greater than 9. |
| Click on the execute query icon | Let us execute the query.
|
| Slide 13
IN Operator |
The IN operator is used to specify multiple values in a WHERE clause.
|
| Slide 14
Syntax of IN Operator
FROM table name WHERE column name IN (value1, value2, ...); |
This is the syntax of the IN operator. |
| Type:
WHERE city IN ('Mumbai', 'Pune', 'Delhi');
|
Let us retrieve students who belong to Mumbai, Pune, or Delhi.
|
| Highlight city IN ('Mumbai','Pune','Delhi') | In this query, the IN operator matches the city with the specified values. |
| Click on the execute query icon | Click on the Execute query icon to execute the query.
|
| Slide 15
|
The NOT IN operator excludes specified values from the result set. |
| Slide 16
FROM table name WHERE column name NOT IN (value1, value2, ...); |
This is the syntax of the NOT IN operator. |
| Type:
SELECT * FROM students WHERE city NOT IN ('Mumbai','Pune'); |
Now let us retrieve students who do not belong to Mumbai or Pune.
|
| Highlight NOT IN ('Mumbai','Pune') | The NOT IN operator filters out the specified cities and returns the remaining records. |
| Click on the execute query icon | Let us execute the query.
|
| Slide 17
|
DISTINCT keyword is used in the SELECT statement to list distinct and unique values.
It removes the duplicate rows or column values from the query result. |
| Slide 18
SELECT DISTINCT column-names FROM table-name WHERE [condition] |
The syntax is as follows:
|
| Type the command:
SELECT DISTINCT city FROM students;
|
Type the query as shown here.
This select statement will retrieve the unique city names from the students table. Let us execute the query. Output will eliminate duplicate values from the specified column city. It only shows distinct city names. |
| With this, we come to the end of this tutorial. | |
| Slide 19
In this tutorial, we have learnt about
|
Let us summarise. |
| Slide 20 +21+22
|
As an Assignment, please do the following. |
| Slide 23
This Spoken Tutorial is brought to you by EduPyramids Educational Private Limited SINE IIT Bombay. Thank you |
Thank You. |