Tidying text: TRIM, UPPER, LOWER
Brightwell's customer data was typed by people, so 'Leeds', 'LEEDS', 'leeds' and 'Leeds ' all appear. To SQL these are four different cities. Clean them up as you query:
TRIM(city)removes spaces from the start and end.UPPER(city)andLOWER(city)change the case.
SELECT COUNT(*)
FROM customers
WHERE LOWER(TRIM(city)) = 'leeds'Functions nest from the inside out: trim first, then lower-case, then compare.
This doesn't change the data, only what the query sees. Fixing the stored data (UPDATE) is a
Tier 4 topic.