INSERT and INNER JOIN together in MySQL?

-2

Hello, is it possible to use INNER JOIN together with INSERT ?

I have a table A with 3 columns X, Y and Z and table B with columns W, X and Y and I need to insert table W in table A, column W? I'm trying this way but I get no results:

INSERT INTO Categoria_cliente_teste  (planejamento) 
SELECT plano_orcamentario 
FROM Categoria_clientes 
INNER JOIN [ON cliente_fornecedor]
    
asked by anonymous 22.03.2018 / 18:21

1 answer

0

Siim is possible !!

According to your description, I created the following example:

1- Create a database with the name "test"

2- I have created the following tables:

Table : a

Columns : x, y and z

-

Table : b

Columns : w, x, y

An example insert would be: INSERT INTO test.a ('y', 'z') SELECT b.x, b.y FROM test.b b;

You can use an inner join to select the results that you want to insert normally, I advise you to give an alias to the query table as it becomes easier to associate with values.

With JOIN: INSERT INTO test.a ('y', 'z') SELECT b.x, b.y FROM test.b b JOIN c ON c.y = b.y;

:)

    
08.04.2018 / 17:17