Databases Reporting with SQL Working with Text Replacing Strings

how to replace

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

whats worong with this code to replace value nanes?

3 Answers

Gabriel Pierce-Lackey
MOD
Gabriel Pierce-Lackey
Treehouse Moderator 10,972 Points
SELECT REPLACE(email, "@", "<at>") AS obfuscated_email FROM customers;

You don't need WHERE or email after select, as you are selecting the REPLACE fuction which has the column or value in the first spot. For the challenge you were also missing the alias

ok but when alias a name it need to be like this : old name AS new name ?

how come that i now need to write AS obfuscated_email FROM customers; without the old name?

Gabriel Pierce-Lackey
MOD
Gabriel Pierce-Lackey
Treehouse Moderator 10,972 Points

Well you're not changing the name of the column or anything, with replace you are changing every instance of "@" to "<at>" in the values of the email column. Since the replace function is already selecting the email column you then only need AS <alias name>, and not repeat the name of column before as.