简体   繁体   中英

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

这很简单:

UPDATE posts SET post_modified = post_date;

此查询应完成以下工作:

UPDATE posts SET post_modified=post_date;

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM