LIKE

Match text against a pattern. % stands for any run of characters, _ for exactly one.

Syntax

column LIKE 'pattern';
  • 'cake%' starts with cake; '%cake' ends with it; '%cake%' contains it.

Example

SELECT name FROM products WHERE name LIKE '%cake%';

The two cake slices.

Tables used: products. Try it in a lesson below.

Common mistakes

  • LIKE is case-sensitive in PostgreSQL. Use ILIKE for a case-insensitive match.

Practise it