SQL Cookbook Lesson

How to convert a string to uppercase in SQL

Learn how to convert a string to uppercase in SQL with examples and explanations from SQLPad.

Problem

You have a column in your database that contains strings, and you want to convert all of those strings to uppercase.

Sample Data

Let's assume you have a table called employees in your database with the following data:

id name
1 John
2 Jane
3 Maxwell
4 Samantha

MySQL Solution

SELECT UPPER(name) AS upper_name FROM employees;

PostgreSQL Solution

SELECT UPPER(name) AS upper_name FROM employees;

MySQL Explanation

In MySQL, the UPPER() function is used to convert a string to uppercase. The SELECT statement is used to select the name column from the employees table. The UPPER(name) part of the query converts the name to uppercase. The AS upper_name part of the query gives the output column a name, in this case, upper_name.

PostgreSQL Explanation

In PostgreSQL, the UPPER() function is used to convert a string to uppercase. The SELECT statement is used to select the name column from the employees table. The UPPER(name) part of the query converts the name to uppercase. The AS upper_name part of the query gives the output column a name, in this case, upper_name. The UPPER() function in PostgreSQL works the same way as in MySQL.

Keep Practicing

Related Cookbook Lessons

View all lessons

Interview Prep

Begin Your SQL, Python, and R Journey

Master 230 interview-style coding questions and build the data skills needed for analyst, scientist, and engineering roles.