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 trialJan Lundeen
5,887 PointsNeed help with REPLACE function question (challenge task 1 of 1) in Reporting with SQL course.
Hi ,
I'm running into a problem with the REPLACE function challenge task in the Reporting with SQL course. Here's the question:
In the customers table there's an email column. Write a query that will retrieve all email addresses but will replace the @ symbol with <at> so they all look like andrew<at>teamtreehouse.com. Alias it as obfuscated_email . Type in your command below.
I've experimented with it, but I can't solve this question. This is my query:
SELECT email AS obfuscated_email FROM customers WHERE REPLACE (email, "@", "<at>") = "<at>";
Here's the error message I received:
Bummer! Try again! I didn't receive any error message below my query (usually, you'll see a more specific message).
Any suggestions?
Thanks,
Jan
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Jan,
You don't need to have a WHERE
condition here.
Instead of selecting the email column unaltered like you're currently doing, you can put your REPLACE
function there.
This way, when it retrieves the email column it will do the replacement and you'll have the correct values you want for that column.
Jan Lundeen
5,887 PointsHi Jason,
Thanks for the suggestion. Is this what you meant? Here's my new version of the query:
SELECT REPLACE(email, "@", "<at>") AS obfuscate_email FROM customers;
Unfortunately, I got the following error:
Bummer! Expecting results like Lauren.Chalkley<at>example.com not Lauren.Chalkley<at>example.com.
It listed a table below. The title was "obfuscate_email". Underneath the title, it listed a bunch of email addresses such as "Lauren.Chalkley<at>example.com".
I'm not sure what I"m missing. On the error message (starts with "Bummer! Expecting....), I'm not sure why it's repeating the same email address. The error message doesn't make any sense to me. Any ideas?
Thanks,
Jan
Jason Anello
Courses Plus Student 94,610 PointsYes that looks good except you have a small typo on the alias. It should be obfuscated_email
Unfortunately the error message wasn't helpful here.
Jan Lundeen
5,887 PointsHi Jason,
Thanks for the catch! That worked.
Jan
Jason Anello
Courses Plus Student 94,610 PointsJason Anello
Courses Plus Student 94,610 PointsThis is the challenge for reference: https://teamtreehouse.com/library/reporting-with-sql/working-with-text/replacing-strings