MySQL插入语句(插入表(列)选择语句) [英] MySQL insert statement (insert into table (columns) select statement)

查看:81
本文介绍了MySQL插入语句(插入表(列)选择语句)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将值插入表的选定列中,但仅插入MySQL语句的结果. select语句本身可以正常工作并返回结果.

I am trying to insert values into selected columns of table, but only insert the results of a MySQL statement. the select statement works correctly by itself and returns the results.

当与insert语句结合使用时,它会失败并显示

when combined with the insert statement it is fails with

error incorrect syntax near `dedspgoods`.`case number`.

有人可以协助我提供正确的语法吗?我的错误语法如下:

Can anyone assist me with the correct syntax? my erronous syntax is as below:

insert into despgoods_alldetails 
  (`case number`, weight, customer, transporttypename) 
values 
( select despgoods.`case number`
       , despgoods.weight
       , despgoods.customer
       , customers.transporttypename 
  from despgoods 
    inner join customers 
      on despgoods.customer = customers.customer )

推荐答案

如果这是有效的SELECT:

select despgoods.`case number`
     , despgoods.weight
     , despgoods.customer
     , customers.transporttypename 
from despgoods 
  inner join customers 
    on despgoods.customer = customers.customer

然后尝试执行此操作(请注意,如果要插入SELECT的结果集,则没有VALUES子句:

Then try this (notice there is no VALUES clause if you want to insert the result set of a SELECT:

insert into despgoods_alldetails 
  (`case number`, weight, customer, transporttypename) 
select despgoods.`case number`
     , despgoods.weight
     , despgoods.customer
     , customers.transporttypename 
from despgoods 
  inner join customers 
    on despgoods.customer = customers.customer

这篇关于MySQL插入语句(插入表(列)选择语句)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆