AnalystPath

Normalize Ingredient Names to Title Case

SQLHardSenior level~15 min

Problem

A recipe app imports ingredient lines from many messy sources, so the casing is inconsistent. Write a solution that rewrites the raw_line column into title case: the first letter of every word becomes uppercase and every other letter becomes lowercase. Words are separated by single spaces, and all existing spaces must be preserved exactly. Return entry_id, raw_line aliased as raw_line, and the cleaned value aliased as tidy_line.

Tables

Example rows — the live problem includes the full dataset.

ingredient_lines
entry_idraw_line
1two cups of FLOUR
2one TEASPOON sea salt
3fresh basil AND ripe tomato

Expected output

Your answer should return 4 rows with the columns entry_id, raw_line, tidy_line.

Starter code (SQL)

SELECT *
FROM ingredient_lines;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions