How to Convert a String to Lowercase in SQL

How to Convert a String to Lowercase in SQL

  • Post category:SQL
  • Post last modified:May 14, 2021
  • Reading time:2 mins read

Use the SQL LOWER() function if you want to convert a string column to lowercase. This function takes only one argument: the column whose values you want to lowercase.

Our database has a table named product with data in the id and name columns.

idname
1Cobb Salad
2Pot roast
3Jerky
4BANANA SPLIT
5CORN bread
6chicken fried Steak

Notice that the naming styles are inconsistent for these products. Let’s display all product names in lowercase.

Solution 1:

SELECT LOWER(name)FROM product;

Here’s the result:

name
cobb salad
pot roast
jerky
banana split
corn bread
chicken fried steak

This function is a good choice if your database is case sensitive and you want to select only records matching a particular string. You can first convert everything to lowercase and then find a match.

Leave a Reply