Using the LIKE Operator
Pattern Matching Using the LIKE Operator
Topic Introduction: "Pattern Matching Using the LIKE Operator" In previous we have known useing many operators, there we have used '=' after the equal operator we give value to search for.
but Sometimes we may not know the exact value to search for. in this case, we can select rows matching a character pattern using the LIKE operator.
The character pattern–matching operation is referred to as a wildcard search. Two symbols can be used to construct the search string.
%: Represents any sequence of zero or more characters
_: Represents any single character
Example:
SELECT last_nameFROM employeesWHERE last_name LIKE 'K%' ;
The SELECT statement above returns the last name from the EMPLOYEES table for any employee whose last name begins with the letter 'K'. Remember that after the like operator the character into a single quotation is case sensitive. If we use the 'k%' instant off 'K%' no data will be returned by this select statement. Because each last name started in upper case.
we may not confirm about the name start with upper or lower in this case we can modify our query like the below example
Example:
SELECT last_nameFROM employeesWHERE lower(last_name) LIKE 'k%' ;
The LIKE operator can be used as a shortcut for some BETWEEN comparisons. The following
the example displays the last names and hire dates of all employees who joined between January 1995
and December 1995.
Example:
SELECT last_name, hire_dateFROM employeesWHERE hire_date LIKE '%95';
No comments