Har*_*jan 1 php mysql sql select insert
所以根据我的需要,我必须将数据从table1复制到table2,为此我使用INSERT SELECT QUERY.这里是 :
$sql = "INSERT INTO `attribute_details_versions`(`attribute_details_id`,`attribute_name`,`attribute_text`,`attribute_value`,`created_at`,`updated_at`) SELECT `attribute_details_id`,`attribute_name`,`attribute_text`,`attribute_value`,`created_at`,`updated_at`FROM `attribute_details`";
Run Code Online (Sandbox Code Playgroud)
在上面的查询中,数据来自attribute_details
复制到attribute_details_versions
表,并且工作正常.
但是version
表格中还有1列,attribute_details_versions
我需要在此列中提交自定义值,如任何整数值(1或2等).这个version column is not exist in
attribute_details`表如何使用SELECT INSERT QUERY插入这个自定义值?
任何帮助,将不胜感激.
如果所有值都需要相同,您只需选择它需要的数字:
$sql = "INSERT INTO `attribute_details_versions`(`attribute_details_id`,`attribute_name`,`attribute_text`,`attribute_value`,`created_at`,`updated_at`, `version `) SELECT `attribute_details_id`,`attribute_name`,`attribute_text`,`attribute_value`,`created_at`,`updated_at`, 2 FROM `attribute_details`";
Run Code Online (Sandbox Code Playgroud)