Reputation: 7
I am trying to write a mysql script that should work as follows but I have no idea how to execute it.
The logic is:
if table1.column1 = table2.column1:
INSERT INTO table3 (col1,col2)
VALUES (table1.column2 , table2.column3)
The tables referred to are all in the same database
Upvotes: 0
Views: 37
Reputation: 164099
Instead of VALUES
you can use a SELECT
statement that joins table1 and table2:
INSERT INTO table3 (col1,col2)
SELECT t1.column2, t2.column3
FROM table1 t1 INNER JOIN table2 t2
ON t1.column1 = t2.column1
Upvotes: 2