PostgreSQL

Like

The LIKE operator is used to search for patterns in a WHERE clause.

Two wildcards can be used with the LIKE operator:

  1. % The percent sign represents, zero, one or many characters.
  2. _ The underscore represents a single character.

For case insensitivity use the iLIKE operator.

Syntax

SELECT <columns> FROM <table-name> 
WHERE <column> LIKE <pattern>; 

Examples

Pattern Description
Where name LIKE 't%' Values starting with 't'
Where name LIKE '%a' Values ending with 'a'
Where name LIKE '%an%' Values that contain 'an'
Where name LIKE '_a%' Values have 'a' as the second letter'
Where name LIKE 'a_%' Values that are ad least two characters and start with 'a'
Where name iLIKE 'd%y' case insensitive values that begin with 'd' and end with 'y'