forked from AlexTheAnalyst/MySQL-YouTube-Series
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Beginner - Where Statement.sql
70 lines (39 loc) · 1.19 KB
/
Beginner - Where Statement.sql
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
#WHERE Clause:
#-------------
#The WHERE clause is used to filter records (rows of data)
#It's going to extract only those records that fulfill a specified condition.
# So basically if we say "Where name is = 'Alex' - only rows were the name = 'Alex' will return
# So this is only effecting the rows, not the columns
#Let's take a look at how this looks
SELECT *
FROM employee_salary
WHERE salary > 50000;
SELECT *
FROM employee_salary
WHERE salary >= 50000;
SELECT *
FROM employee_demographics
WHERE gender = 'Female';
#We can also return rows that do have not "Scranton"
SELECT *
FROM employee_demographics
WHERE gender != 'Female';
#We can use WHERE clause with date value also
SELECT *
FROM employee_demographics
WHERE birth_date > '1985-01-01';
-- Here '1990-01-01' is the default data formate in MySQL.
-- There are other date formats as well that we will talk about in a later lesson.
# LIKE STATEMENT
-- two special characters a % and a _
-- % means anything
SELECT *
FROM employee_demographics
WHERE first_name LIKE 'a%';
-- _ means a specific value
SELECT *
FROM employee_demographics
WHERE first_name LIKE 'a__';
SELECT *
FROM employee_demographics
WHERE first_name LIKE 'a___%';