0

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.

4
  • Do you want to replace the Hash of every row in the table, or just the top 1000? Commented Jun 29, 2016 at 15:39
  • There are 1000 hashes specifically, so both would equal all of them. But yes all of them, could I use an UPDATE statement? What would the syntax look like if I did? Commented Jun 29, 2016 at 15:40
  • And are you sure this is mysql, TOP is sql server. Commented Jun 29, 2016 at 15:40
  • My mistake, this is SQL and not MySQL, I meant to tag sql-server instead of mysql. I will change that. Commented Jun 29, 2016 at 15:44

2 Answers 2

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

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'

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.