ds08541 2014-12-04 10:35
浏览 156
已采纳

PHP MySQL将数据从一个表插入另一个表

I want to fetch data from one table to another, i have took references from many sites and Stackoverflow but I wasn't able to solve error. The last field is the applicant field where I would like to send Default value 'No'. I want to do this whole thing in single query

insert into user_identity (login_no, customer_id, prename, 
fullname, mobile, dob, age, applicant) values
select login_id, customer_id, c_prename, CONCAT_WS(' ',`c_firstname`,`c_lastname`),
 c_mobile, dob, age, 'No' from customer where id = '1'
  • 写回答

2条回答 默认 最新

  • douyou8047 2014-12-04 10:44
    关注

    the keyword VALUES is not needed,try this..

    insert into user_identity (login_no, customer_id, prename, 
    fullname, mobile, dob, age, applicant) 
    select login_id, customer_id, c_prename, CONCAT_WS(' ',c_firstname,c_lastname),
     c_mobile, dob, age, 'No' from customer where id = '1'
    

    refer this.. http://dev.mysql.com/doc/refman/5.1/en/insert-select.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • dqrzot2791 2014-12-04 10:47
    关注

    When we are inserting from another table, we do not use the keyword values as we are not providing the values implicitly. we are fetching it from another table. So in that sense, to create a table as an exact replica of another we can do something like this

    CREATE TABLE EMP as SELECT * FROM EMPLOYEE
    

    Similarly while inserting we do something like this

    Insert into <tablename>(column name) select (column name) from <Table name>
    
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Erasure Code纠删码表
  • ¥15 用vite创建的vue3项目,404重定向不起作用??
  • ¥15 关于#c语言#的问题:一个球从80米高度自由落下,每次落地后反弹的高度为原高度的一半计算6次小球反弹的高度.(反弹结果取整,使用走走for循环结构)
  • ¥15 SurfaceControl的screenshot问题
  • ¥15 基于51单片机的oled菜单代码,要C语言,模块化编程!
  • ¥15 JAVAswing,设计一个扑克牌什么的
  • ¥50 python ctypes调用dll实现分析
  • ¥40 用python解决数据统计问题
  • ¥100 是否有方案能通过抓包分析得到移动应用的名称和包名信息?
  • ¥15 opencv检测不到轮廓