the tao
the tao

Reputation: 341

How do I fill an entire column in mysql with hash generated from username in that row

The query I have so far is :

create table users_csv_import
(
  username varchar(255),
  reg_link varchar(255)
);

insert into users_csv_import (username, reg_link)
values ('kns2184', 'NULL');
insert into users_csv_import (username, reg_link)
values ('kns2185', 'NULL');
insert into users_csv_import (username, reg_link)
values ('kns2186', 'NULL');
insert into users_csv_import (username, reg_link)
values ('kns2187', 'NULL');
insert into users_csv_import (username, reg_link)
values ('kns2188', 'NULL');

update users_csv_import
set reg_link = md5(username in row should go here?)
where reg_link='NULL';

So what I would like to do is for every row generate md5 hash from username in that row. I do not want to use a php loop, I would like to do this through mysql because I assume it will be much faster then something like an array of generated hashes via php.

http://sqlfiddle.com/#!2/da389/1

Upvotes: 1

Views: 766

Answers (1)

BWS
BWS

Reputation: 3846

Just do what you say in your post (almost):

update users_csv_import
set reg_link = md5(username)
where reg_link IS NULL;

Upvotes: 1

Related Questions