MySQL insert语句(插入表(列)select语句)
我试图将值插入到表的选定列中,但只插入 MySQL 语句的结果。 select 语句本身可以正常工作并返回结果。
当与插入语句结合使用时,它失败了,
error incorrect syntax near `dedspgoods`.`case number`.
谁能帮助我使用正确的语法?我的错误语法如下:
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 )
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.
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 )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果这是有效的
SELECT
:那么请尝试此操作(请注意,如果您想要插入
SELECT
的结果集,则没有VALUES
子句:If this is the
SELECT
that works:Then try this (notice there is no
VALUES
clause if you want to insert the result set of aSELECT
:正如@EdHeal所述,您需要将
case number
括在引号或反引号之间,因为列名称中有空格(事实上CASE
是保留字实际上只是一个有趣的细节,但这并不是在这种情况下破坏查询的原因)。As stated by @EdHeal, you'll need to enclose
case number
between quotes or backticks as there is a space in the column name (the fact thatCASE
is a reserved word is actually only an interesting detail, but that's not what breaks the query in this case).case
是保留字。需要将“案件编号”放在引号中。case
is a reserved word. Need to put 'case number' in quotes.这里它去
那里。那应该可以正常工作。请记住,不要用空格命名变量,因为这可能会变得非常棘手。我认为你的 case 编号有误,因为当 case 是 MySQL 中的函数时,它之间有一个空格。如果您还需要什么,请告诉我。
here it goes
there. that should work fine. Remember, do not name your variables with spaces, because it can get real tricky. I think you had an error in case number because it has a space in between, when case is a function in MySQL. Let me know if you need anything else.