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 trialJohn Richter
2,351 Pointshow to replace a single piece of a randomly placed character in a substring.
How do I return a list of email addresses replacing the '@' with '<at>'.
2 Answers
Jennifer Nordell
Treehouse TeacherHi there, John Richter! You would use the REPLACE
function. The REPLACE
function takes the column you want to look at, the string you want to replace, and the string you want to replace it with. They must be in that order.
The challenge is asking you to select the emails and replace the string '@'
with the string '<at>'
and then give it an alias of obfuscated_email
. I'd be curious to know what you had originally tried. There may have just been a syntax error somewhere along the way.
SELECT REPLACE(email, '@', '<at>') AS obfuscated_email FROM customers;
The above line says select all emails but replace the "@" with "<at>" then give it the alias "obfuscated_email" and this is located in the customers
table.
Hope this helps!
John Richter
2,351 PointsThank you for clarifying Jennifer!
John Richter
2,351 PointsJohn Richter
2,351 PointsJennifer Nordell , Here is what i had
SELECT * from customers REPLACE(email,'@','<at>') AS "obfuscated_email";
I'm still not quite sure why this wouldn't work.
Isn't this query asking - Return all customers, change the returned email with the following details?
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherHi, John Richter! I'm pretty sure that would result in an SQL error because the fields you're selecting must be specified before the table. Also, the challenge is asking for only the email column and you are selecting all columns. Also, the field name for the alias does not need quotation marks.
SELECT <columns> FROM table;
If you do
*
you're selecting all columns and wouldn't be able to specify an alias for any one of those individual columns.