通过mysql使用select from other表插入

通过mysql使用select from other表插入,mysql,Mysql,尝试使用以下命令插入到其他表中,但既不会引发错误,也不会插入: INSERT INTO orderlines(orderLineItemName,orderLineItemnotes,itemID,itemPriceNormal,categoryID ,regionID,orderLineItemQuantity,orderLineItemPriceUnit,orderLineItemDiscount,orderLineItemSubTotal, orderLineItemTotalTax ,

尝试使用以下命令插入到其他表中,但既不会引发错误,也不会插入:

INSERT INTO orderlines(orderLineItemName,orderLineItemnotes,itemID,itemPriceNormal,categoryID
,regionID,orderLineItemQuantity,orderLineItemPriceUnit,orderLineItemDiscount,orderLineItemSubTotal,
orderLineItemTotalTax 
,orderLineItemStatus,userID,orderLineItemDateCreated,orderLineItemDateUpdated,ordercode) 
SELECT quoteLineItemName, quoteLineItemnotes, itemID, itemPriceNormal, categoryID, regionID, 
quoteLineItemQuantity, quoteLineItemPriceUnit, quoteLineItemDiscount, quoteLineItemSubTotal, 
quoteLineItemTotalTax, quoteLineItemStatus, userID, quoteLineItemDateCreated, quoteLineItemDateUpdated,
'Complete' as orderstatus 
FROM quoteslines 
WHERE quotelineitemid = 1
试试这个

INSERT INTO orderlines
SELECT quoteLineItemName, quoteLineItemnotes, itemID, itemPriceNormal, categoryID, regionID, 
quoteLineItemQuantity, quoteLineItemPriceUnit, quoteLineItemDiscount, quoteLineItemSubTotal, 
quoteLineItemTotalTax, quoteLineItemStatus, userID, quoteLineItemDateCreated,              quoteLineItemDateUpdated,
 'Complete' as orderstatus 
FROM quoteslines 
WHERE quotelineitemid = 1 
最后一列值使用“'Complete”作为订单状态是否正确。我不这么认为。如果要在最后一列中输入值“Complete”,请在下面尝试

INSERT INTO orderlines(orderLineItemName,orderLineItemnotes,itemID,itemPriceNormal,categoryID
,regionID,orderLineItemQuantity,orderLineItemPriceUnit,orderLineItemDiscount,orderLineItemSubTotal,
orderLineItemTotalTax 
,orderLineItemStatus,userID,orderLineItemDateCreated,orderLineItemDateUpdated,ordercode) 

SELECT quoteLineItemName, quoteLineItemnotes, itemID, itemPriceNormal, categoryID, regionID, 
quoteLineItemQuantity, quoteLineItemPriceUnit, quoteLineItemDiscount, quoteLineItemSubTotal, 
quoteLineItemTotalTax, quoteLineItemStatus, userID, quoteLineItemDateCreated, quoteLineItemDateUpdated,
'Complete'
FROM quoteslines 
WHERE quotelineitemid = 1

select part本身是否返回任何行?是,它返回1row@a_horse_with_no_name是的,你说得对。修复了错误因此,这与问题中的代码有什么不同(除了没有列出目标列之外),只有在表
quoteslines
中有一列
Complete
时,这才有效。您怎么知道有这样一个列?那么现在这与原始语句有什么不同呢?从select查询中,我们得到的数据仅用于插入到orderlines表中。我们只需要quoteslines表的列数据,而不需要列名称。