Reputation: 352
How can I update the username field with the email field value for all the records on the table.
update table1 set username = (select email from table1);
I know it is wrong method. But I am not getting the correct way to do this.
Upvotes: 0
Views: 46
Reputation: 9894
Sample Data:
Uname Email
a [email protected]
b [email protected]
c [email protected]
If you want your output to be:
Uname Email
[email protected] [email protected]
[email protected] [email protected]
[email protected] [email protected]
Then use:
UPDATE table1 set Uname = EMAIL
If you want your output to be
Uname Email
[email protected] [email protected]
b [email protected]
c [email protected]
Then use,
UPDATE TABLE1 SET UNAME = EMAIL WHERE UNAME='a';
If you want your output to be
Uname Email
[email protected] [email protected]
[email protected] [email protected]
[email protected] [email protected]
Then use,
UPDATE TABLE1 SET UNAME = (SELECT EMAIL FROM TABLE1 WHERE UNAME='a');
Upvotes: 2