Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何更改此MySql表的所有记录中此字段的值?_Mysql_Sql_Database_Rdbms - Fatal编程技术网

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

如何更改此MySql表的所有记录中此字段的值?,mysql,sql,database,rdbms,Mysql,Sql,Database,Rdbms,我有以下情况 在一个MySql数据库中,我有一个posts表。此表包含以下两个字段:post\u modified和post\u date 对于posts表中的每个记录,我需要将post_modified字段的值设置为post_date 如何执行对所有表记录执行此操作的查询 Tnx这很简单: UPDATE posts SET post_modified = post_date; 这很简单: UPDATE posts SET post_modified = post_date; 此查询应执行以

我有以下情况

在一个MySql数据库中,我有一个posts表。此表包含以下两个字段:post\u modifiedpost\u date

对于posts表中的每个记录,我需要将post_modified字段的值设置为post_date

如何执行对所有表记录执行此操作的查询

Tnx

这很简单:

UPDATE posts SET post_modified = post_date;
这很简单:

UPDATE posts SET post_modified = post_date;

此查询应执行以下操作:

UPDATE posts SET post_modified=post_date;

此查询应执行以下操作:

UPDATE posts SET post_modified=post_date;

您只需使用
更新
,无需任何条件即可更新所有记录:

update posts set post_modified = post_date
根据数据库中的设置,可能不允许不带条件的更新。然后,您将添加一个虚拟条件,告诉数据库您实际上想要更改每个记录:

update posts set post_modified = post_date where 1 = 1

您只需使用
更新
,无需任何条件即可更新所有记录:

update posts set post_modified = post_date
根据数据库中的设置,可能不允许不带条件的更新。然后,您将添加一个虚拟条件,告诉数据库您实际上想要更改每个记录:

update posts set post_modified = post_date where 1 = 1

意味着输出的每一行都应该有相同的数据?您至少会尝试阅读MySQL文档。意味着输出的每一行都应该有相同的数据?您至少会尝试阅读MySQL文档。@KM。我也会投票给你们,15秒内有三个答案:-)看到人们也为这种简单的事情问解决方案,他们称自己为程序员/开发人员,这很有趣:@KM。我也会投票给你们,15秒内有三个答案:-)看到人们也为这种简单的事情提出解决方案,他们称自己为程序员/开发人员,这很有趣:)