0

At localhost I want to replace all of emails with their usernames. This is not works:

UPDATE `users` SET 'email'='username'

What is the working code?

John Woo
  • 258,903
  • 69
  • 498
  • 492
csaron92
  • 1,035
  • 2
  • 10
  • 20

2 Answers2

1

Assuming you have a field called username in the data:

update users set email = username;

Your code is confusing back quotes with regular quotes (which are used only to delimit strings). You could also write:

update `users` set `email` = `username`;

Back quotes are used to enclose column and table names, particularly when they have unusual characters (like spaces) or conflict with reserved names.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

because you have wrap the column name with single quotes. Remove it and it will work.

UPDATE users SET email = 'username'

backticks are only used to escape reserved keywords or column names and tables names that have special characters on it. More explanation on the link below.

but if you mean to copy the values of column username into email, you need to remove the quotes on both column,

UPDATE users SET email = username
Community
  • 1
  • 1
John Woo
  • 258,903
  • 69
  • 498
  • 492