Fix Names in a Table - Problem
You are given a table Users with user information where names contain mixed case characters.
Problem: Fix all names so that only the first character is uppercase and the rest are lowercase.
Requirements:
- Only the first character should be uppercase
- All remaining characters should be lowercase
- Return results ordered by
user_id
Table Schema
Users
| Column Name | Type | Description |
|---|---|---|
user_id
PK
|
int | Primary key - unique user identifier |
name
|
varchar | User name with mixed case characters |
Primary Key: user_id
Note: Names consist of only lowercase and uppercase characters
Input & Output
Example 1 — Mixed Case Names
Input Table:
| user_id | name |
|---|---|
| 1 | aLice |
| 2 | bOB |
| 3 | CHARLIE |
Output:
| user_id | name |
|---|---|
| 1 | Alice |
| 2 | Bob |
| 3 | Charlie |
💡 Note:
The query transforms each name by making the first character uppercase and all remaining characters lowercase. aLice becomes Alice, bOB becomes Bob, and CHARLIE becomes Charlie.
Example 2 — Single Character Names
Input Table:
| user_id | name |
|---|---|
| 1 | a |
| 2 | B |
Output:
| user_id | name |
|---|---|
| 1 | A |
| 2 | B |
💡 Note:
For single character names, only the first character transformation applies. The SUBSTRING(name, 2) returns empty string, so we just get the uppercase first character.
Constraints
-
1 ≤ user_id ≤ 1000 -
nameconsists of only lowercase and uppercase characters -
1 ≤ name.length ≤ 100
Visualization
Tap to expand
Understanding the Visualization
1
Input
Users table with mixed case names
2
Transform
Apply string case functions
3
Output
Properly formatted names
Key Takeaway
🎯 Key Insight: Use string functions to systematically format text data in SQL
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code