The SQL LIKE Operator
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards used in conjunction with the LIKE operator:
- % - The percent sign represents zero, one, or multiple characters
- _ - The underscore represents a single character
Table Name: Loan
1) Find any branch name that starts with "D"?
SQL QUERY: select branch_name from loan where branch_name LIKE '%D'
Description: '%' The percent sign represents zero, one, or multiple
characters and " D " in our searching character
2) Find any branch name that ends with "n"?
SQL QUERY: select branch_name from loan where branch_name LIKE '%n'
Description: '%' The percent sign represents zero, one, or multiple
characters and " n " in our searching character
3) Find any branch name that have 'r' in any position?
SQL QUERY: select branch_name from loan where branch_name LIKE '%r%'
Description: '%' The percent sign represents zero, one, or multiple
characters and " r " in our searching character
4) Find any branch name that has 'r' in the second position?
SQL QUERY: select branch_name from loan where branch_name LIKE '_r'
Description: '_' The underscore represents a single character and " r " in
our searching character. We search " r " in 2nd position so
we can use 1st position in one underscore.
5) Find any branch name that has 'R' in the four position?
SQL QUERY: select branch_name from loan where branch_name LIKE '___R'
Description: '_' The underscore represents a single character and " R " in
our searching character. We search " R " in four positions so
we can use 1st to 3rd position in 3 underscores.
6) Find any branch name that starts with 'm' and ends with 'l' ?
SQL QUERY: select branch_name from loan where branch_name LIKE 'm%l'
Description: '%' The percent sign represents zero, one, or multiple
characters and " m " and " l " in our searching character.
This problem says 1st positions have " m " and the last
position have " l " character so we set 1st positions in "m"
and last position in "l".
7) Find any branch name that starts with "D" or "Y"?
SQL QUERY: select branch_name from loan where branch_name LIKE '%D' or
branch_name LIKE '%Y'
branch_name LIKE '%Y'
Description: '%' The percent sign represents zero, one, or multiple
characters and " D " or "Y" in our searching character
8) Find any branch name that ends with "n" or "k"?
8) Find any branch name that ends with "n" or "k"?
SQL QUERY: select branch_name from loan where branch_name LIKE '%n'
or branch_name LIKE '%k'
or branch_name LIKE '%k'
Description: '%' The percent sign represents zero, one, or multiple
characters and " n " or " k " in our searching character
9) Find any branch name that exactly 3 characters lengths?
SQL QUERY: select branch_name from loan where branch_name LIKE '___'
Description: '_' The underscore represents a single character and our
our searching query only shows all 3 characters branch name
so we know "_" one underscore represents a single character
so we can use 3 underscores in this.
10) Find any branch name that starts with ' M ' and are at least 3 characters in
length?
SQL QUERY: select branch_name from loan where branch_name LIKE 'M_%_%'
Description: '%' The percent sign represents zero, one, or multiple
9) Find any branch name that exactly 3 characters lengths?
SQL QUERY: select branch_name from loan where branch_name LIKE '___'
Description: '_' The underscore represents a single character and our
our searching query only shows all 3 characters branch name
so we know "_" one underscore represents a single character
so we can use 3 underscores in this.
10) Find any branch name that starts with ' M ' and are at least 3 characters in
length?
SQL QUERY: select branch_name from loan where branch_name LIKE 'M_%_%'
Description: '%' The percent sign represents zero, one, or multiple
characters and "_" The underscore represents a single
character and this problem says " M " must have in 1st
positions in this branch name & branch name length in
minimum of 3 characters. so we first set "M" in the first
position then set 2 underscores to represent in other
2 characters.
<-- Back Page
character and this problem says " M " must have in 1st
positions in this branch name & branch name length in
minimum of 3 characters. so we first set "M" in the first
position then set 2 underscores to represent in other
2 characters.
<-- Back Page
0 Comments
If you have any doubts, Please let me know