Menu
CoddyTech

Search Text with ILIKE

Part of the First Queries section of Coddy's PostgreSQL journey. Lesson 9 of 20.

PostgreSQL ILIKE matches text without distinguishing letter case according to the active locale. A percent sign matches any number of characters; an underscore matches exactly one character. Use single quotes around the pattern.

Input table products:

idnamecategorypricestockactivenote
1Maptravel125TrueNULL
2Notebookbooks80TrueRecycled
3Atlasbooks243FalseNULL
4Mughome128TrueBlue
5lamphome302FalseClearance
6Mini maptravel610TrueNULL
SELECT id, name FROM products WHERE name ILIKE 'm%' ORDER BY id;

Map, Mug and Mini map begin with m regardless of its case. A pattern without percent signs matches the entire text rather than searching inside it. These exercises use ASCII names so locale differences do not affect the answer.

Use ILIKE for case-insensitive pattern matching. Surround a search term with % to find it anywhere.

challenge icon

Challenge

Easy

Return id and name for products whose name contains map in any letter case. Order by id.

The input tables are shown in the test panel. Each run starts from fresh data. Return the named columns in the stated order; do not hard-code the displayed rows.

Try it yourself

-- Write your SQL here.
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in First Queries

Practice on your own: PostgreSQL playground