The document discusses various clauses and operators that can be used in the WHERE clause of an SQL query. It explains clauses like WHERE, AND, OR that allow filtering records based on conditions. It also describes various operators like =, <, >, BETWEEN, LIKE, IN, NOT that can be used to write those conditions. Examples are given for each clause and operator to illustrate their usage in a WHERE clause.
3. msbacademy.org
Where Clause
Where Clause is used to extract only those records that
satisfied the given condition, like fetch only those student record
which has more than 75 marks
4. msbacademy.org
When use where clause ?
1. To retrieve the only specific record
2. To delete the only specific record
3. To update only specific record
7. msbacademy.org
And Clause
And clause is used to combine two or more than two
conditions together. In this case, you need must be true both
condition then return the result otherwise it won’t return any
result.
Suppose you want to get only students records who have
more than 75 marks and CSE branch in that case you can
combine these two conditions by using AND clause.
9. msbacademy.org
OR Clause
OR clause is used to combine two or more than two
conditions together, In this case, you need at least one condition
must true then only it will return the result.
Suppose you want to get only those students records who
have more than 75 marks or CSE branch in that case you can be
combine these two conditions by using OR clause.
13. msbacademy.org
Like Operator
Like Operator is used in a WHERE clause to search for a
specified pattern in a column.
Suppose you want to search those students records whose
names starts with M alphabet.
15. msbacademy.org
LIKE operators with '%' and '_‘Wildcard Characters
LIKE Operator Description
WHERE student_name LIKE ‘ra%' Finds any values that starts with “ra"
WHERE student_name LIKE '%ra' Finds any values that ends with “ra"
WHERE student_name LIKE '%sr%' Finds any values that have “sr" in any position
WHERE student_name LIKE '_m%' Finds any values that have “m" in the second
position
WHERE student_name LIKE ‘e_%_%' Finds any values that starts with “e" and are at
least 3 characters in length
WHERE student_name LIKE ‘s%d' Finds any values that starts with “s" and ends with
“d"
16. msbacademy.org
Between Operator
1. BETWEEN returns values that fall within a given range.
2. BETWEEN is a shorthand for >= AND <=.
3. BETWEEN operator is inclusive: begin and end values are
included.
18. msbacademy.org
IN operator
The IN operator allows you to specify multiple values in a
WHERE clause.
The IN operator is a shorthand for multiple OR conditions
20. msbacademy.org
IN operator Examples
SELECT * FROM student
WHERE Country IN (‘india', ‘usa', ‘china');
Or
SELECT * FROM student
WHERE Country IN (SELECT Country FROM employee);