Mysql - Insert multiple products in one order

Asked

Viewed 1,223 times

0

I have an order table in mysql, where the total order value, the date, the customer’s id, and the products that were purchased should be informed. The problem that these products are in the product table. I would like to know how to insert these various products with the sql command? Insert only one product I know good. I will use this in a C#Web application, where the customer selects the products in a grid and confirms the order.

  • 1

    Hello @Vanderson, Welcome to Stackoverflow-en. Check this link: http://answall.com/help/how-to-ask. Try to include as much information as possible in your questions. In this case, maybe detail the way your database was mapped.

1 answer

-1

Vanderson, suppose this is your table compras with the following columns:

id, total_pedido, data, id_cliente

You’d have to have a table pedido_detalhes which had the following columns:

idproduto, idcompra

Therefore, whenever a "buying", she would generate a ID that would be saved together with all products purchased in the table pedido_detalhes.

  • I got it, buddy, I really saw the help.

  • Friend would have how to show how would the sql code for this insertion ? Pq do the simple insert I get good: Insert into order (valuePedido, dataPedido, id_client) values (2000, '2016-02-23 00:00', 1). But how would this sql work with the requested table?

Browser other questions tagged

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