Brightlane's logistics system identifies customers in cities whose name contains new somewhere — a quick way to surface New York, Newcastle, New Orleans, and similar locations.
Write a query to return the ID, name, and city of every customer whose city contains new, regardless of capitalization.
Assumptions:
- The
customerstable has one row per customer with anid, aname, and acity. - A qualifying customer has a
citycontainingnewsomewhere in the string, with case ignored.
Output:
- One row per qualifying customer, with columns
id,name, andcity.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
id,
name,
city
FROM
customers
WHERE
city ILIKE '%new%' The shape
ILIKE '%new%' matches the substring new anywhere inside the city name, regardless of capitalization. The leading and trailing % make the match positional-agnostic, and ILIKE folds the case so New York, new orleans, and NEWCASTLE all qualify under one pattern.
Clause by clause
SELECT id, name, cityreturns the three columns the logistics report needs. Including the matchedcitylets the reader confirm why each row was kept.FROM customersreads the customer table.WHERE city ILIKE '%new%'keeps the rows where the city containsnewsomewhere. With%on both sides, the substring can sit at any position; withILIKEinstead ofLIKE, the column's casing does not have to match the pattern's casing.
The trap
% is the wildcard that allows surrounding characters. Without the leading %, the pattern ILIKE 'new%' would only match cities that start with new, dropping Newcastle if it were spelled differently and missing any city where the substring sits in the middle. Without the trailing %, the pattern would require the city to end on new. Both wildcards are load-bearing for an "anywhere in the string" match.
You practiced ILIKE '%pattern%' — case-insensitive substring matching across a column whose values may use varying capitalization conventions.