-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLIKE with % WildCard in SQl.txt
More file actions
64 lines (59 loc) · 3 KB
/
LIKE with % WildCard in SQl.txt
File metadata and controls
64 lines (59 loc) · 3 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
// LIKE with % WildCard in SQL
-> The Like operator is used to search for a specified pattern in a column.
syntax: SELECT * FROM table_name WHERE column_name LIKE 'pattern';
// Wild cards
-> Wild cards are used to search for data within a table. These characters are used with thr LIKE operator.
% -> zero or more characters
_ -> One single character
[charlist] -> Sets and ranges of characters to match
[^charlist] or [!charlist] -> Matches only a character NOT specified within the brackets
1. % -> zero or more characters
'hello%' - all starting with hello Ex: hello testing
ex: SELECT * FROM student_reg WHERE name LIKE 'bi%';
+------+-------+---------+------+---------+
| s_id | name | address | dob | fees |
+------+-------+---------+------+---------+
| 104 | BIMAl | KTM | NULL | 1001.23 |
+------+-------+---------+------+---------+
'%testing' - All ending with testing Ex: hello testing
ex:SELECT * FROM student_reg WHERE name LIKE '%i';
+------+------+---------+------------+----------+
| s_id | name | address | dob | fees |
+------+------+---------+------------+----------+
| 103 | HARI | PKR | 2001-01-12 | 10000.52 |
+------+------+---------+------------+----------+
'%in%' - all containing with in ex: hello testing
SELECT * FROM student_reg WHERE name LIKE '%ma%';
+------+-------+---------+------------+-----------+
| s_id | name | address | dob | fees |
+------+-------+---------+------------+-----------+
| 104 | BIMAl | KTM | NULL | 1001.23 |
| 105 | KAMAL | PKR | 1956-12-12 | 100000.12 |
+------+-------+---------+------------+-----------+
2. - one single character
'testing_ -> '-starting with show then any character Ex testing
Ex: SELECT * FROM student_reg WHERE s_id LIKE '10_';
+------+---------+---------+------------+-----------+
| s_id | name | address | dob | fees |
+------+---------+---------+------------+-----------+
| 101 | RAM | KTM | 1998-12-15 | 1000.23 |
| 102 | SITA | KTM | 2001-10-11 | 200000.12 |
| 103 | HARI | PKR | 2001-01-12 | 10000.52 |
| 104 | BIMAl | KTM | NULL | 1001.23 |
| 105 | KAMAL | PKR | 1956-12-12 | 100000.12 |
| 106 | SITA KC | PKR | 1998-02-02 | 20000.12 |
+------+---------+---------+------------+-----------+
'_tin' -> ant charaxter the tin. Ex testing
ex:SELECT * FROM student_reg WHERE s_id LIKE '_04';
+------+-------+---------+------+---------+
| s_id | name | address | dob | fees |
+------+-------+---------+------+---------+
| 104 | BIMAl | KTM | NULL | 1001.23 |
+------+-------+---------+------+---------+
't_s_g -> t then any character then s then any character, then g ex: testing
ex: SELECT * FROM student_reg WHERE s_id LIKE '1_3';
+------+------+---------+------------+----------+
| s_id | name | address | dob | fees |
+------+------+---------+------------+----------+
| 103 | HARI | PKR | 2001-01-12 | 10000.52 |
+------+------+---------+------------+----------+