UPDATESQL

Unit 2, lesson 2 · LIKE, LOWER

Searching text with LIKE and LOWER

Find the desk gear

LIKE matches a pattern instead of exact text. In a pattern, % stands for any run of characters, including none, so where you put it decides what matches. In PostgreSQL, LIKE also cares about capitals: 'Desk speaker pair' starts with a capital D, so it does not match '%desk%'. LOWER(name) turns a value into all lowercase letters, so LOWER('Desk speaker pair') is 'desk speaker pair'. Lowercase the column and write the pattern in lowercase, and capitals stop mattering. Here is what each pattern finds in the products table:

PatternMatches names that
LIKE 'desk%'starts with desk
LIKE '%desk'ends with desk
LIKE '%desk%'has desk anywhere
LIKE 'desk'is exactly desk (no %)
Example
SELECT name
FROM products
WHERE LOWER(name) LIKE '%light%';

Your task

A shopper searched for "desk". List the name and price of every product with "desk" anywhere in its name, whatever the capitalization.

Tables you will use: products

Try it in your browserFree, no sign-up. Your query is checked as you go.