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 trialJames Ackerman
14,099 PointsReporting with SQL - REPLACE() function
I'm having trouble with the code challenge in SQL regarding the REPLACE() function. The challenge reads...
"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 ."
I've tried the following among other attempts...
SELECT email FROM customers WHERE REPLACE (email, "@", "<at>") = "<at>" AS "obfuscated_email";
SQL Error: near "AS": syntax error
5 Answers
Steven Parker
231,269 PointsA WHERE
clause would come after the FROM
, but I don't think you need one for this challenge. The misplaced keyword is likely causing your issue. And you have more than one select term but no comma separating them.
You were right to remove the equality comparison and extra term, they would not be used in the SELECT
clause.
If there's still more to the issue please include a link to the course page to facilitate a more complete analysis.
Steven Parker
231,269 PointsBoth the REPLACE
function and the alias would be part of the SELECT
clause, and come before the FROM
.
James Ackerman
14,099 PointsThanks Steven, but I'm still having issues. I moved the REPLACE function and alias before FROM and still wasn't making progress. I've watched the video about 5 times now, and I'm just not sure what the proper syntax would be to accomplish this.
> SELECT email WHERE REPLACE(email, "@", "<at>") = "<at>" AS "obfuscated_email" FROM customers;
SQL Error: near "AS": syntax error
I tried a few things which didn't really make sense to me, such as removing the quotes from the "<at>" string and the "obfuscated_email" string. Again, no luck. I also tried removing the
= "<at>"
portion because the error seems to be near AS with no luck.
James Ackerman
14,099 PointsLink to the video: Replacing Portions of Text in the Reporting with SQL class
Steven Parker
231,269 PointsIt passed for me after removing the WHERE
, the extra select term ("email"), and the comparison operator along with the term following that.
James Ackerman
14,099 PointsYeah, got it after doing what you mentioned, although I have no idea why it worked. The syntax doesn't seem to follow what was explained in the prior video.
Thanks much for your assistance. I've been stuck in this section for a while now.