Helix Systems' HR team is auditing the management layer ahead of an org chart update. A management role is any title that contains the word manager somewhere in it.
Write a query to return the name and title of every employee currently in a management role.
Assumptions:
- The
employeestable contains every active and former employee at Helix Systems. - Job titles use mixed capitalisation across departments — some are stored with a capital
M(e.g.,Engineering Manager), others with a lowercasem(e.g.,account manager). The match must catch both.
Output:
- One row per qualifying employee, with columns
nameandtitle.
Schema · hr 4 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
title
FROM
employees
WHERE
title ILIKE '%manager%' The shape
ILIKE '%manager%' is a case-insensitive substring match — % on both sides lets manager appear anywhere in the title, and ILIKE makes the comparison ignore capitalisation so titles stored with either capital M or lowercase m both pass.
Clause by clause
SELECT name, titlereturns the two columns the HR audit needs: the employee's name and the title that classifies them as a manager.FROM employeesreads the employee roster.WHERE title ILIKE '%manager%'keeps only the rows whosetitlecontains the substringmanagersomewhere in it, with case ignored.Engineering Managermatches becauseManagersits at the end.account managermatches becausemanageris there in lowercase. A title likeDirector of Engineeringdoesn't match because the substring isn't present at all.
Why this and not LIKE '%manager%'
LIKE is case-sensitive in PostgreSQL. LIKE '%manager%' would match account manager but miss Engineering Manager — the capital M doesn't match the lowercase m in the pattern. Flip the pattern to '%Manager%' and the opposite gap opens. Neither form catches both spellings on its own.
ILIKE is the PostgreSQL extension that makes the comparison case-insensitive. The pattern is written in whatever case is convenient, and the engine matches without regard to capitalisation on either side. Same wildcard rules as LIKE — % for any sequence, _ for one character — only the casing semantics change.
The trap
Forget that LIKE is case-sensitive and the query silently undercounts. There is no error, no warning. The HR team gets a result set that looks reasonable but is missing every manager whose title is stored in the non-matching case. The fix is to reach for ILIKE anytime the underlying data has inconsistent capitalisation and the match must catch both cases, or to standardise the data upstream so plain LIKE is enough.
You practiced case-insensitive pattern matching with ILIKE. PostgreSQL's LIKE is case-sensitive by default — ILIKE is the recurring fix any time the data has inconsistent capitalisation and the match must catch both cases without preprocessing.