简体   繁体   English

如何在此MySql表的所有记录中更改此字段的值?

[英]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. MySql数据库中,我有一个posts表。 This table contains the following 2 fields: post_modified and post_date 该表包含以下2个字段: post_modifiedpost_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 对于帖子表中存在的每条记录,我需要将post_modified字段的值设置为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来更新所有记录:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何更改MySQL中特定字段的所有记录 - how to change all records of a specific field in mysql 如何用uniqueid()填充MySQL表中所有记录的字段? - How to populate a field of all of the records in a MySQL table with uniqueid()? 我在phpmyadmin表中有一个记录列表,我想更改所有记录中一个字段的值 - I have a list of records in a phpmyadmin table, I want to change the value of one field in all the records 当两个表字段在MySQL中具有相同的值时,如何忽略将表中的记录插入到另一个表中? - How to ignore inserting records from a table to another table when both table field has same value in MySQL? 如何使用触发器(MySQL)在插入时更改同一表的字段值 - How to change a field value of the same table on insert using trigger (MySQL) 更新一个表中某个字段的所有记录,该字段的值仅在另一个表中 - Update all the records of a field in a table whose value is only in another table 对于mysql中的特定字段,返回计数> 1的表中的所有记录 - Return all records in a table with count > 1 for specific field in mysql 根据字段值更改mysql表联接 - Change mysql table join based on field value Mysql如何从一个表中选择列值不是X和Y的所有记录 - Mysql How to select all records from one table where column value is not both X and Y 显示mysql表中的所有记录 - Displaying all records in a mysql table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM