-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL Filtering Data - Where Clause and Operators.sql
More file actions
113 lines (90 loc) · 2.24 KB
/
SQL Filtering Data - Where Clause and Operators.sql
File metadata and controls
113 lines (90 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-- Filtering Data
-- WHERE Clause
-- Filter data based on specified conditions.
-- Syntax -
-- select col1, col2,...
-- from table_name
-- where condition
-- Query1:
select *
from employeedemographics
where firstname = 'Jim';
-- Comparison Operators:
-- =, <>(!=), <, >, <=, >=
-- Query2:
select *
from employeedemographics
where firstname <> 'Jim';
-- Query3:
select *
from employeedemographics
where age > 30;
-- Query4:
select *
from employeedemographics
where age < 30;
-- Query5:
select *
from employeedemographics
where age <= 30;
-- Query6:
select *
from employeedemographics
where age >= 30;
-- Logical Operators:
-- ALL, AND, IS NULL, IS NOT NULL, BETWEEN, IN, LIKE, EXISTS, NOT, OR, SOME
-- Query7:
select *
from employeedemographics
where age <= 32 AND gender = 'Male';
-- Query8:
select *
from employeedemographics
where age <= 32 OR gender = 'Male';
-- Query9:
select *
from employeedemographics
where firstname IS NULL;
-- Query10:
select *
from employeedemographics
where firstname IS NOT NULL;
-- Query11:
select *
from employeesalary
where salary between 40000 and 50000;
-- Query12:
select *
from employeedemographics
where firstname IN ('Jim', 'Michael');
-- LIKE
-- The LIKE operator compares a value to similar values using a wildcard operator.
-- SQL provides two wildcards used in conjunction with the LIKE operator:
-- 1. The percent sign ( %) represents zero, one, or multiple characters.
-- 2. The underscore sign ( _) represents a single character.
-- Query13:
select *
from employeedemographics
where lastname like 'S%';
-- Query14:
select *
from employeedemographics
where lastname like '%s%';
-- Query15:
select *
from employeedemographics
where lastname like '_e%';
-- ALL
-- The ALL operator compares a value to all values in another value set.
-- The ALL operator must be preceded by a comparison operator and followed by a subquery.
-- syntax -
-- comparison_operator ALL (subquery)
-- Query16:
select Firstname, Lastname
from employeedemographics
where Salary >= ALL ( select salary from employeesalary where jobtitle = 'HR');
-- ANY
-- Similary to ALL operator
-- The ANY operator compares a value to any value in a set according to the condition.
-- EXISTS
-- The EXISTS operator tests if a subquery contains any rows.