Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Reporting with SQL Working with Text Changing the Case of Text Columns

LOWER()

Hello,

SELECT * FROM customers WHERE LOWER(email) = 'andrew@teamtreehouse.com' ;

The table has 'Andrew@teamtreehouse.com'. What does this query do? Does it make all the emails in the table change to a lower case, no I suppose not, since we say that one email is = 'andrew@teamtreehouse.com' . Yes, I am lost as to what the where clause in this query does when all the emails in the table have email addresses that start in a capital letter. I have always thought LOWER () and UPPER () changes values to lower or capital, but I don't think this query changes anything. Please help

thanks

2 Answers

Boban Talevski
Boban Talevski
24,793 Points

A year later, but here it goes :).

What this query will do, is going to compare ALL values in the email column, changed to lower case for the purpose of the comparison ONLY, to the hardcoded value we give it "andrew@teamtreehouse.com". It doesn't change anything in the database.

This is how it goes. Get the value of the first row of the table, TEMPORARILY make the value in the email column lower case, check the lower case version if it's the same as the hardcoded value "andrew@teamtreehouse.com" and if it is, add the whole row to the result of the query (with the email IN ITS ORIGINAL FORM since we are using * and not doing any manipulation on the returned results). Do the same for the second row and so on till we go over all rows in the customers table.

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi there,

Yes, LOWER() takes a column as a parameter and displays the strings inside the columm as lower case. Used on it's own this willl change all the values in the given column. You can get more specific changes using the WHERE clause! :)

Good luck :)