Answer the question
In order to leave comments, you need to log in
How to make a request so that it is not duplicated?
Good afternoon friends, tell me please, business. requests to the database and ran into a problem.
Parsing parses the goods, if you run it once, it will parse everything perfectly, but when I click again, it duplicates the goods.
I do not know how to combine 2 requests into one ID key. There is a generation of SELECT MAX (product_id)
I have 2 queries, one without the other does not display.
The first product itself:
INSERT INTO s_products (url,name,brand_id,meta_title,meta_keywords,meta_description)
VALUES ((SELECT MAX(product_id) FROM s_lang_products),'%Название%','0','%Название%','%Название%','%Название%')
ON DUPLICATE KEY UPDATE `url` =
(SELECT MAX(product_id) FROM s_lang_products),
`name` = '%Название%',
`brand_id` = '0',
`meta_title` = '%Название%',
`meta_keywords` = '%Название%',
`meta_description` = '%Название%';
REPLACE INTO s_lang_products (lang_id, product_id, name, meta_title, meta_keywords, meta_description)
SELECT 1, id, name, meta_title, meta_keywords, meta_description
FROM s_products;
Answer the question
In order to leave comments, you need to log in
Good afternoon. If I understand correctly, then in your s_product the key is url + name, and since url is always generated, regardless of name, but just the maximum value of product_id in s_product_lang, then the key will never be a duplicate. Theoretically, name + meta_title can be a key, but you can determine it only by knowing the structure of your database more precisely
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question