-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlike-ilike-25.psql
49 lines (38 loc) · 1.39 KB
/
like-ilike-25.psql
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
/**
String matching:
If we want to to match against a general pattern in a string
- All emails ending in '@gmail.com'
- All names that begin with 'A'
The LIKE operator allows us to perform pattern matching against string data with the use
of wildard charcaters:
- Percent %
- Matches any sequence of characters
- Underscore _
- Matches any single character
All names that begin with an 'A' uppercase
- WHERE name LIKE 'A%'
All names that end with a lowercase 'a'
- WHERE name LIKE '%a'
LIKE is case sensitive, we can use ILIKE whis is case-insensitive.
Using the underscore allows us to replace
just a single character.
- Get all Mission Impossible films
- WHERE LIKE 'Mission Impossible _' Where we could match one, two, three etc...
You can use multiple underscores.
Imagine if we had version string codes in the format 'Version#A4', 'Version#B7, etc...
- WHERE value LIKE 'Version#__'
We can also combine pattern matching operators to create more complex patterns
- WHERE name LIKE '_her%'
- Cheryl
- Theresa
- Sherri
*/
-- Examples
-- Let's get all first names that start with s in both case and case-insensitive.
-- Case sensitive
SELECT * FROM customer
WHERE first_name LIKE 'S%' AND last_name LIKE 'M%';
-- Case insensitive
SELECT * FROM customer
WHERE first_name ILIKE 'S%' AND last_name ILIKE 'M%';
SELECT title FROM film;