M
M
MasterCopipaster2021-09-21 23:50:52
MySQL
MasterCopipaster, 2021-09-21 23:50:52

Mysql Duplicate entry 'MD309756-Mitsubishi' for key '/tmp/#sql19a3e3_55aee_29.' Why does this error occur at all?

I make a request:

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;


But an error occurs:
Duplicate entry 'MD309756-Mitsubishi' for key '/tmp/#sql19a3e3_55aee_29.


But why does she show up at all? according to DQL, I have a unique field in the resulting table, only 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? - thus if the data in the temporary table CREATE TEMPORARY TABLE `tmp` there is a hogwash.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question