Insert records from one table into another in MySql?

0

I am having difficulty inserting data from one table into another, for example I have the budget table that has the items, but the items can be from different vendors, and when this budget is approved it should generate the purchase orders for the respective suppliers, eg:

  

Budget table

Assuming that SELECT * FROM orcamento WHERE orcamento = 330; , I have:

  

Purchaseordertable

Iwouldliketocreateapurchaseorderforeachvendorasinthetablebelow,beingdismembered,asfollows:

I would like to create a purchase order with all items of the vendor as in the example of the purchase order table where an order was created with items Id 2 and 4 that correspond to the same vendor of code 55, I would like to use this functionality directly in the bank, informing only the budget id.

I'm using php with mysql, not mysqli.

    
asked by anonymous 04.01.2018 / 13:59

1 answer

1

You can use INSERT along with SELECT .

For example:

INSERT INTO ordem_compra (id, id_orcamento, fornecedor)
SELECT id, id_orcamento, id_fornecedor FROM orcamento WHERE orcamento = 330;
    
04.01.2018 / 14:06