插入任意值并在同一语句MYSQL中选择

时间:2014-05-15 06:58:34

标签: mysql sql

我正在尝试做类似

的事情
INSERT INTO tbl_order_detail (key_order,key_product,fld_unit_price,fld_quantity) 
VALUES (<value1>, <value2>,
SELECT fld_unit_price,fld_quantity FROM tbl_product WHERE key_product = <value2>);

这个的正确语法是什么?

2 个答案:

答案 0 :(得分:5)

INSERT INTO tbl_order_detail 
    (key_order,key_product,fld_unit_price,fld_quantity)
SELECT <value1>, <value2>, fld_unit_price,fld_quantity 
FROM tbl_product 
WHERE key_product = <value2>;

答案 1 :(得分:1)

     INSERT
INTO tbl_order_detail
  (
    key_order,
    key_product,
    fld_unit_price,
    fld_quantity
  )
SELECT 
    <value1>,
    <value2>,
    fld_unit_price,
    fld_quantity
  FROM tbl_product
  WHERE key_product = <value2>
;