Data Engineering

Search & Replace Strings in SQL

SQL Mastery Team
April 13, 2026
4 min read

Welcome to **Day 82**. Today we're doing "Find and Replace" at scale using the `REPLACE` function.

The Concept

`REPLACE(string, search_for, replace_with)`. It's that simple.

Real-World Example: Updating Domain Names

Your company just rebranded from `old-startup.com` to `big-corp.com`. You need to update all the email addresses in the database.

SELECT

REPLACE(email, '@old-startup.com', '@big-corp.com') as new_email

FROM users;

Real-World Example: Cleaning URLs

Sometimes URLs come in with `https://www.` and some without. You can standardize them:

SELECT

REPLACE(url, 'https://www.', '') as clean_url

FROM page_views;

Warning: It's Case Sensitive

In most databases, `REPLACE` will not find 'Admin' if شما search for 'admin'. You might need to use `LOWER()` first to be safe.

Your Task for Today

Take a column with a recurring typo and use `REPLACE` to show what the corrected version would look like.

*Day 83: Splitting Strings (UNNEST and STRING_TO_ARRAY).*

Ready to put your knowledge into practice?

Join SQL Mastery and learn through interactive exercises.