condition like in sql query php code example
Example 1: 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 2: sql where value like a or b
SELECT Id, ProductName, UnitPrice, Package
FROM Product
WHERE ProductName LIKE 'Cha_' OR ProductName LIKE 'Chan_'