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 Replacing Strings

Taylor Han
Taylor Han
2,406 Points

REPLACE function with SQL

Having trouble with new functions and then aliasing. Did I use the REPLACE function correctly? Thanks!

Post your code so we can take a look.

Taylor Han
Taylor Han
2,406 Points

SELECT * customers WHERE REPLACE(email, "@", "<at>") AS obfuscated_email;

Here is what I have tried, wanting to pull all emails from a table and replace "@" with "<at>" and alias it. Thanks!

1 Answer

Steven Parker
Steven Parker
231,268 Points

You're using the function correctly, but there are some query syntax issues. The item being selected comes first (in this case, only the modified email), then the alias, and the table after the "FROM" keyword:

SELECT REPLACE(email, "@", "<at>") AS obfuscated_email FROM customers;

You don't need WHERE since you are returning data from every row.