Page 136 - SQL
P. 136
SELECT * FROM Employees WHERE FName LIKE '__n%';
(two underscores are used before 'n' to skip first 2 characters)
Id FName LName PhoneNumber ManagerId DepartmentId Salary Hire_date
06-08-
3 Ronny Smith 2462544026 2 1 600
2015
23-03-
4 Jon Sanchez 2454124602 1 1 400
2005
Single character match
To broaden the selections of a structured query language (SQL-SELECT) statement, wildcard
characters, the percent sign (%) and the underscore (_), can be used.
The _ (underscore) character can be used as a wildcard for any single character in a pattern
match.
Find all employees whose Fname start with 'j' and end with 'n' and has exactly 3 characters in
Fname.
SELECT * FROM Employees WHERE FName LIKE 'j_n'
_ (underscore) character can also be used more than once as a wild card to match patterns.
For example, this pattern would match "jon", "jan", "jen", etc.
These names will not be shown "jn","john","jordan", "justin", "jason", "julian", "jillian", "joann"
because in our query one underscore is used and it can skip exactly one character, so result must
be of 3 character Fname.
For example, this pattern would match "LaSt", "LoSt", "HaLt", etc.
SELECT * FROM Employees WHERE FName LIKE '_A_T'
Match by range or set
Match any single character within the specified range (e.g.: [a-f]) or set (e.g.: [abcdef]).
This range pattern would match "gary" but not "mary":
SELECT * FROM Employees WHERE FName LIKE '[a-g]ary'
This set pattern would match "mary" but not "gary":
https://riptutorial.com/ 118

