like query code example
Example 1: like sql
WHERE CustomerName LIKE 'a%'
WHERE CustomerName LIKE '%a'
WHERE CustomerName LIKE '%or%'
WHERE CustomerName LIKE '_r%'
WHERE CustomerName LIKE 'a__%'
WHERE ContactName LIKE 'a%o'
Example 2: MySQL LIKE
The LIKE operator is a logical operator that tests whether a string contains a specified pattern or not. Here is the syntax of the LIKE operator:
expression LIKE pattern ESCAPE escape_character
This example uses the LIKE operator to find employees whose first names start with a:
SELECT
employeeNumber,
lastName,
firstName
FROM
employees
WHERE
firstName LIKE 'a%';
This example uses the LIKE operator to find employees whose last names end with on e.g., Patterson, Thompson:
SELECT
employeeNumber,
lastName,
firstName
FROM
employees
WHERE
lastName LIKE '%on';
For example, to find all employees whose last names contain on , you use the following query with the pattern %on%
SELECT
employeeNumber,
lastName,
firstName
FROM
employees
WHERE
lastname LIKE '%on%';
Example 3: like in sql
(Like) Operator for partial searches using wildcard '%' and '_'
For Example:
Select * From Employees
Where last_name LIKE '_a%';
Example 4: sql like
eturns true if the operand value matches a pattern.
Example: Returns true if the user’s first_name ends with ‘son’.
SELECT * FROM users
WHERE first_name LIKE '%son';
Example 5: sql where value like a or b
SELECT Id, ProductName, UnitPrice, Package
FROM Product
WHERE ProductName LIKE 'Cha_' OR ProductName LIKE 'Chan_'
Example 6: like sql
syntax => SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
the pattern.
SELECT * FROM Persons
WHERE City LIKE 's%'