Mysql query too long

I have a problem with this mysql query. It takes vmore like 1 day to fulfill ...

Inquiry:

INSERT INTO traduction  
(traduction.`id`,traduction.`traduction`,traduction.`language`,traduction.`type`) 
(
 SELECT cities.id,cities.name, '', 'city' FROM cities 
  WHERE cities.id NOT IN 
   (
    SELECT traduction.`id` FROM traduction WHERE traduction.type='city' GROUP BY id
   )
);

I made an explanation expanded by choice 2, and he talks about a DEPENDENT SUBCURIER, so the second choice is reproduced for each choice by city, but I find it useless.

Is there a way in mysql or another sql server that can allow this?

Or maybe complete another request.

The idea is that if the city does not have a profession, the name of the city should be recorded in the results table. Then I just need to look in the trading table, and not in the city table.

+3
source share
2 answers

You can try something like this

INSERT INTO traduction   
(traduction.`id`,traduction.`traduction`,traduction.`language`,traduction.`type`)  
( 
SELECT  cities.id,
        cities.name, 
        '', 
        'city' 
FROM    cities  LEFT JOIN
        (
            SELECT  traduction.`id` 
            FROM    traduction 
            WHERE   traduction.type='city' 
            GROUP BY id 
        ) s ON cities.id = s.id
WHERE   s.ID IS NULL
);

, , , traduction.type traduction.id cities.id

INSERT INTO traduction   
(traduction.`id`,traduction.`traduction`,traduction.`language`,traduction.`type`)  
( 
SELECT  cities.id,
        cities.name, 
        '', 
        'city' 
FROM    cities  LEFT JOIN
        (
            SELECT  DISTINCT
                    traduction.`id` 
            FROM    traduction 
            WHERE   traduction.type='city'
        ) s ON cities.id = s.id
WHERE   s.ID IS NULL
);

:

INSERT INTO traduction    
(traduction.`id`,traduction.`traduction`,traduction.`language`,traduction.`type`)   
(  
SELECT  cities.id, 
        cities.name,  
        '',  
        'city'  
FROM    cities 
WHERE   NOT EXISTS (
                        SELECT  DISTINCT 
                                traduction.`id`  
                        FROM    traduction  
                        WHERE   traduction.type='city'
                        AND     cities.id = traduction.id 
                    )
);
+2

traduction,

0

Source: https://habr.com/ru/post/1732746/


All Articles