2014-05-15 66 views
0

我試圖做類似插入任意值,並選擇在同一語句MYSQL

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>); 

,這是什麼的正確語法?

+0

在MySQL中不可能。你需要兩個語句:首先運行'insert'語句,然後運行'select' –

+1

或者反過來呢? – Jekk

回答

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
 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> 
;