Insert multiple columns and tables into a variable in mysql

Asked

Viewed 344 times

0

I am in a simple dilemma (I believe) I have 3 tables in question.. the Associated table and the Request table and the box. The associate fields are: id, ref_by, name .... The fields of the request are: pedido_id, pedido_client, pedido_date, pedido_status, pedido_total_product. The box fields are: id, id_client,client,id_doc,value,date

What I need to do is this: I need to enter in the box table, all orders that have the status 4. However I need to fill with the data: id_client, client (name), id_doc(order code), value (order value), date (order date).

Can someone who has understood my dilemma help me? Ahh.. remembering that it is all in mysql direct.

  • And what are the primary and foreign keys of your tables?

  • It is not clear what your doubt is

1 answer

0

You can select by joining the membership and order tables and use the result to add to the Caixaent table.

According to the structure you showed, the query would look like this:

insert into caixaEnt(id_cliente,cliente,id_doc,valor,data)
select a.id, a.nome, b.pedido_id, b.pedido_total_produto, b.pedido_data from associado as a inner join pedido as b ON a.id = b.pedido.cliente WHERE b.pedido_status = 4

Here is a tutorial with other examples:

http://www.mysqltutorial.org/mysql-insert-into-select/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.