The LIKE keyword
Part of the Fundamentals section of Coddy's SQL journey — lesson 20 of 72.
The LIKE keyword is used to check the similarities of strings. For example, if we want to fetch all of the records that the name starts with the letter a then we will use the LIKE keyword.
Two main wildcards are used:
%- means any number of characters_- means exactly one character
For example:
%a- means any string that ends withaa%- means any string that starts witha
%a%- means any string that containsa_a%- means that the letterais the second character in the string
%a__- means that the string containsain the 3rd from last place
To use it we will write:
SELECT col1, col2, ...
FROM table1
WHERE col1 LIKE '%a__'Challenge
EasyAvailable tables and columns:
<strong>people</strong>:<strong>id</strong>,<strong>name</strong>
Fetch all of the people whose name starts with K (uppercase) and ends with a (lowercase) and order the results by the names in descending order.
Cheat sheet
The LIKE keyword is used to check string similarities with wildcards:
%- means any number of characters_- means exactly one character
Common patterns:
%a- ends withaa%- starts witha%a%- containsa_a%-ais the second character%a__-ais in the 3rd from last place
SELECT col1, col2, ...
FROM table1
WHERE col1 LIKE '%a__'Try it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns