LIKE Operator

The LIKE operator is used, for example, in a WHERE clause to search a column based on a specified pattern. In the construction of the LIKE query, two constructs are frequently used:

  • % representing zero, one, or more characters
  • _ representing a single character

Important! In MS Access, (*) is used instead of (%) and (?) is used instead of (_).

Formula:

SELECT column1
, column2
, column3
FROM Table1
WHERE column1 LIKE pattern1;

Important! The LIKE operator can be combined with logical operators AND and OR.

Below are use cases for LIKE with % and _

WHERE EmployerName LIKE 'p%' - starts with the letter 'p'

WHERE EmployerName LIKE '%p' - ends with the letter 'p'

WHERE EmployerName LIKE '%group%' - contains the word 'group'

WHERE EmployerName LIKE '_g%' - second letter is 'g'

WHERE EmployerName LIKE 'p_%' - starts with the letter 'p' and has at least 2 characters

WHERE EmployerName LIKE 'p%a' - starts with the letter 'p' and ends with the letter 'a'

Interesting article? Share further!

Leave A Comment