-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFiltering Data by Operators SQL Queries.sql
More file actions
74 lines (69 loc) · 1.35 KB
/
Copy pathFiltering Data by Operators SQL Queries.sql
File metadata and controls
74 lines (69 loc) · 1.35 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
use mydatabase;
/* Filtering Data
Comparision Operators*/
/* = operator
Retrieve all customers from USA*/
select *
from cus
where countrys='USA';
-- REtrieve all customers who are not from germany
select *
from cus
where countrys!='USA';
-- REtrieve all customers with score greater than 500
select *
from cus
where countrys!='USA'
and scores>500;
-- REtrieve all customers with score greater than equal 500
select *
from cus
where countrys!='USA'
and scores>=500;
-- REtrieve all customers with score less than 500
select *
from cus
where countrys!='USA'
and scores<500;
-- REtrieve all customers with score less than equal 500
select *
from cus
where countrys!='USA'
and scores<=500;
-- Logical Operators - AND, OR, NOT
-- AND
select *
from cus
where countrys!='Germany'
and scores<=500;
-- OR
select *
from cus
where countrys!='USA'
or scores<=500;
-- Not
select *
from cus
where not scores < 500;
-- Range Operator - BETWEEN
select *
from cus
where scores between 100 and 500;
select *
from cus
where scores >=100 and scores<=500;
-- Retrieve countries with either from Germany or USA(IN, NOT IN)
select *
from cus
where countrys in('Germany','USA');
select *
from cus
where countrys not in('Germany','USA');
-- Find all customers names starts with m
select *
from cus
where first_names like 'M%';
-- r in the 3rd position
select *
from cus
where first_names like '__r%';