all cheat sheets

SQL strings and pattern matching cheat sheet

LIKE, SUBSTR, INSTR, REPLACE, case handling and concatenation.

Matching

LIKE wildcards
SELECT name FROM customers WHERE name LIKE 'A%';

% = any run of characters, _ = one character

Case-insensitive match
SELECT name FROM products WHERE LOWER(name) LIKE '%desk%';

Slicing and building

First name
SELECT SUBSTR(name, 1, INSTR(name, ' ') - 1) AS first FROM customers;

Postgres: SPLIT_PART(name, ' ', 1)

Concatenate
SELECT name || ' (' || country || ')' AS label FROM customers;
Replace and trim
SELECT TRIM(REPLACE(name, 'in ', '-inch ')) FROM products;

Try it live

sql · editable
loading editor…

Practice it

learn sql step by step →

More cheat sheets

Ready for interview-level questions? Pro unlocks the full company problem set.