AndreaNobili
AndreaNobili

Reputation: 42997

How to change the value of this field in all the records of this MySql table?

I have the following situation.

In a MySql database I have a posts table. This table contains the following 2 fields: post_modified and post_date

For each record present in the posts table I need set the value of post_modified field with the value into the post_date

How can I do a query that do this work on all the table records?

Tnx

Upvotes: 0

Views: 68

Answers (3)

Guffa
Guffa

Reputation: 700562

You would just use an update without a condition to update all records:

update posts set post_modified = post_date

Depending on the settings in the database an update without a condition might not be allowed. Then you would add a dummy condition just to tell the database that you actually want to change every record:

update posts set post_modified = post_date where 1 = 1

Upvotes: 1

Simon
Simon

Reputation: 1605

This query should do the job :

UPDATE posts SET post_modified=post_date;

Upvotes: 2

VMai
VMai

Reputation: 10336

That's an easy one:

UPDATE posts SET post_modified = post_date;

Upvotes: 3

Related Questions