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
.
id | name |
---|---|
1 | Cobb Salad |
2 | Pot roast |
3 | Jerky |
4 | BANANA SPLIT |
5 | CORN bread |
6 | chicken 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.