SQL LIKE

LIKE finds text that matches a pattern. The percent sign % stands for any number of characters (including none) and the underscore _ stands for exactly one character.

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

Syntax

WHERE column LIKE 'pattern'

Try it yourself

Run the example below on a real PostgreSQL database, then change it and run it again. Nothing to install, no sign-up.

like.sql · PostgreSQL
Loading editor…

Examples

1. Contains

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

Any name that contains Desk.

2. Starts with

SELECT first_name FROM customers WHERE first_name LIKE 'A%';

Names beginning with A.

3. Case-insensitive

SELECT name FROM products WHERE name ILIKE '%usb%';

ILIKE ignores case.

Common mistakes

  • Forgetting the wildcards: LIKE 'Desk' only matches the exact text Desk.
  • Expecting LIKE to ignore case in PostgreSQL.

Practice: test yourself

This challenge is from our interactive course. Write the query and press Check answer.

Challenge · 20 pts

Return the name of every product whose name contains the word 'Desk'.

challenge.sql · PostgreSQL
Loading editor…

FAQ

How do I search for a literal % sign?

Escape it with a backslash: LIKE '%50\%%'.

Learn SQL step by step

65 hands-on exercises, streaks, a leaderboard and a certificate.

Start free →