Делаю запрос:
INSERT
INTO
analogs (article, brand, brand_id, product_id, analog_product_id) SELECT
DISTINCT laximo_crosses.article1 as article,
ddd.main_brand as brand,
laximo_crosses.title1 as title,
products.id as analog_product_id,
laximo_crosses.id AS l_id
from
`tmp_table_fast`
inner join laximo_crosses ON
laximo_crosses.id = `tmp_table_fast`.id
inner join main_brands ON
main_brands.brand_names = laximo_crosses.brand2
inner join main_brands as ddd ON
ddd.brand_names = laximo_crosses.brand1
inner join products ON
products.normalized_article = laximo_crosses.article2
and products.brand_id = main_brands.brand_id;
Но возникает ошибка:
Duplicate entry 'MD309756-Mitsubishi' for key '/tmp/#sql19a3e3_55aee_29.
Но почему она вообще появляется? у меня по DQL
уникальное поле в результирующей таблице
только ID
-- planetavto.analogs definition
CREATE TABLE `analogs` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`article` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`brand` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`title` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`brand_id` varchar(191) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`product_id` bigint(20) unsigned DEFAULT NULL,
`analog_product_id` bigint(20) unsigned DEFAULT NULL,
`l_id` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `analogs_article_index` (`article`),
KEY `analogs_brand_index` (`brand`),
KEY `analogs_product_id_index` (`product_id`),
KEY `analogs_analog_product_id_index` (`analog_product_id`),
KEY `analogs_brand_id_index` (`brand_id`),
CONSTRAINT `analogs_analog_product_id_foreign` FOREIGN KEY (`analog_product_id`) REFERENCES `products` (`id`),
CONSTRAINT `analogs_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
WTF? - при этом если инсертить данные во временную таблицу
CREATE TEMPORARY TABLE `tmp` происходит таже фигня.