Jekk
Jekk

Reputation: 598

Insert arbitrary value and select in the same statement MYSQL

I am trying to do something like

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

What is the proper syntax for this?

Upvotes: 0

Views: 189

Answers (2)

Olesya Razuvayevskaya
Olesya Razuvayevskaya

Reputation: 1168

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

Upvotes: 1

Lennart - Slava Ukraini
Lennart - Slava Ukraini

Reputation: 7181

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

Upvotes: 5

Related Questions