SELECT INSERT within PHP Mysql INSERT

1

I have the following code:

$sql = mysql_query("INSERT INTO TB004_PRODUTO_FORNECEDOR ( TB002_CODIGO, TB003_CODIGO )     
                  SELECT TB003_CODIGO, 1 AS Codigo FROM TB003_PRODUTO WHERE TB003_DESCRICAO = '$name_02'
                  VALUES ( '$name_01', Codigo )");

How can I select the product code inside insert so it just inserts the code?

    
asked by anonymous 15.11.2016 / 19:20

1 answer

4

Hello, I do not know if I understood correctly, but from what I understand you want to insert the result of a select. If so, just do + - like this:

INSERT INTO TB004_PRODUTO_FORNECEDOR ( TB002_CODIGO, TB003_CODIGO )     
VALUES ('$name_01',(SELECT TB003_CODIGO FROM TB003_PRODUTO WHERE TB003_DESCRICAO = '$name_02'))
    
16.11.2016 / 01:40