doupu3635 2014-09-19 10:10
浏览 57
已采纳

INSERT SELECT Query中的自定义值

So As per my needs I have to copy the data from table1 to table2 and for that I'm using the INSERT SELECT QUERY. Here it is :

$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`";

In above query the data from attribute_details is copying to attribute_details_versions table and which is working fine.

But There is 1 more column version in table attribute_details_versions and i need to submit the custom value like any integer value (1 or 2 or etc.) in this column. this version column is not exist inattribute_details` table so how can i insert this custom value using SELECT INSERT QUERY ?

Any Help would be appreciated.

  • 写回答

1条回答 默认 最新

  • dongyigua4468 2014-09-19 10:12
    关注

    If it needs to be the same for all values, you can simply select the number it needs to be:

    $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`";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度