php - Insert from one table into another (with extra values) (MySQL) -


had search can find stuff on inserting 1 table another.

i have query takes data 1 table , inserts another:

insert tbl_orders (product_id, customer_id)    select product_id, customer_id tbl_basket    customer_id = '" . $_session['user'] . "'"); 

what want data included. example insert product_id , customer_id based of other table, , insert values not located in table.

i have tried no luck:

insert tbl_orders (product_id, customer_id, order_status)    select product_id, customer_id, \'placed\' tbl_basket    customer_id = '" . $_session['user'] . "'" 

any ideas? thank you.

if want insert data table, can tried query:

insert tbl_orders (product_id, customer_id, order_status)  select product_id, customer_id, 'order_status' tbl_basket  customer_id = 'example' 

if have data in second table, can join second table this:

insert tbl_orders (product_id, customer_id, order_status)  select product_id, customer_id, t2.order_status tbl_basket t1  join tbl_basket2 t2 on t1.id = t2.id t1.customer_id = 'example' 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -