A
A
AJ2015-08-13 18:41:25
MySQL
AJ, 2015-08-13 18:41:25

How to run the entire SELECT through INSERT SELECT?

I am not very strong in MySQL. Gradually gaining skill and now I have a problem. Select unique values ​​from one table, then search the other with these values ​​and write the result to a new one.
How to record the question does not arise. INSERT SELECT. How to choose too. And here's how it doesn't even come to mind that I chose to drive through INSERT SELECT.
I tried to google the analogue of foreach in php, only in MySQL, but somehow something is not very good.
In general, I would be grateful for an example of such a request.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2015-08-13
@dmitryKovalskiy

rather confusing explanation of the problem. you need either a complex select for a clear selection of what to add or a "cursor"

R
Rsa97, 2015-08-13
@Rsa97

INSERT INTO `result_table` (...)
    SELECT ...
        FROM `table1` AS `t1`
        JOIN (
             SELECT DISTINCT ... FROM `table2`
        ) AS `t2` ON ...
        WHERE ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question