Fix Names in a Table
Task: Fix the names so that only the first character is uppercase and the rest are lowercase. Return the result table ordered by user_id.
Table: Users
+-------------+-------------+
| Column Name | Type |
+-------------+-------------+
| user_id | INT |
| name | varchar(40) |
+-------------+-------------+
Input: Users table:
+---------+-------+
| user_id | name |
+---------+-------+
| 1 | aLice |
| 2 | bOB |
+---------+-------+
Output:
+---------+-------+
| user_id | name |
+---------+-------+
| 1 | Alice |
| 2 | Bob |
+---------+-------+ View Reference Solution & Explanation ▼
This solution uses string manipulation functions to format the text to find the required output.
SELECT user_id, UPPER(SUBSTR(name, 1, 1)) || LOWER(SUBSTR(name, 2)) AS name FROM Users ORDER BY user_id;