John Smittheeerrs
John Smittheeerrs

Reputation: 103

Update column from a table with newly generated passwords

So I have the code for generating the kind of passwords I want which is

SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 6) AS Paswoord

How do I make this work for all the 60 rows I already have at once. I think it might be with Inner Join etc. I have tried some stuff but the all fail.

Thanks for reading.

Upvotes: 0

Views: 57

Answers (3)

Bohemian
Bohemian

Reputation: 425198

UPDATE USER SET 
PASSWORD = SUBSTRING(MD5(RAND(ID)) FROM 1 FOR 6)
WHERE PASSWORD IS NULL -- or whatever consition matches rows you want to update

Upvotes: 1

bonCodigo
bonCodigo

Reputation: 14361

Try this please: sorry made a typo - anyway the above two answers are there to help you :)

UPDATE maintable
    SET maintable.column = (SELECT SUBSTRING(MD5(RAND()) FROM 1 FOR 6))

Upvotes: 0

John Woo
John Woo

Reputation: 263803

UPDATE tableName
SET columnName = SUBSTRING(MD5(RAND()),1,6)

Upvotes: 1

Related Questions