SQL LIKE operator is used in SQL Where clause to search for specified pattern in a column. The SQL LIKE clause basically used to compare a value to similar values using the wildcard operators in SQL.
Here are the types of wildcards listed, which are used in conjunction with the LIKE operator in SQL:
Here is the general form of the LIKE operator in SQL:
SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;
Here are the list of examples shows the WHERE part having different LIKE clause with percentage (%) and underscore (_) operators:
(i) This finds any values start with 200:
WHERE SALARY LIKE '200%'
(ii) This finds any values which have 200 in any position:
WHERE SALARY LIKE '%200%'
(iii) This finds any values which ends with 2:
WHERE SALARY LIKE '%2'
This finds any values which have a 2 in the second position and have 3 at the end:
WHERE SALARY LIKE '_2%3'
(iv) This finds any values which have 00 in the second and the third positions:
WHERE SALARY LIKE '_00%'
(v) This finds any values start with 2 and at least 3 character long:
WHERE SALARY LIKE '2_%_%'
(vi) This finds any values in a five digit number, must start with 2 and end with 3:
WHERE SALARY LIKE '2___3'
Here is an example of SQL LIKE Operator. Suppose we have the following table named CUSTOMERS in the database :
Following is an example, which will display all the records from the table named CUSTOMERS where SALARY starts with 8:
SELECT * FROM CUSTOMERS WHERE SALARY LIKE '8%';
After querying the above statement, you will get the following output: