Keagan Dalley
Keagan Dalley

Reputation: 103

SQL Replace entire row with value

So I have a row in a table which contains 300 randomly generated hashes. I would like to replace all of them with one specific hash. How could I write a query that replaces every value in said table with my specific hash? Right now my query looks like:

SELECT TOP 1000 [Hash]
    FROM [x].[y].[z]

X/Y/Z are different in my query obviously. However I do not know how I can then replace every value in the top 1000 Hashes with my specific hash.

Upvotes: 0

Views: 1455

Answers (2)

skim
skim

Reputation: 171

Use self inner join to update just the top 1000, like below. Note that I replaced TOP with LIMIT since we are talking about MySQL

UPDATE [x].[y].[z] XYZ
INNER JOIN 
 (
  select SOME_KEY_FROM_XYZ from [x].[y].[z] LIMIT 1000
 ) ZYX ON XYZ.SOME_KEY_FROM_XYZ = ZYX.SOME_KEY_FROM_XYZ
SET Hash = 'OneSpecificHash'

Upvotes: 0

Bort
Bort

Reputation: 7618

UPDATE [x].[y].[z]
SET Hash = 'OneHashToRuleThemAll'

No WHERE condition will update the entire table. Make sure this is what you want.

Upvotes: 1

Related Questions