A
A
ART42018-01-29 17:51:48
MySQL
ART4, 2018-01-29 17:51:48

SQL query to enter data?

Good afternoon, I'm doing one parsing. Here sql I blunted something.
Parsing is fine, but when downloading the goods, something is being prepared.
Parses the characteristics of the product, Screenshot of the database
d8857d5e3a.png
Here is a screen of the admin panel of the product itself
2284c5ee18.png
It seems to fill in, everything is in its place. But the question arose: the
product ID goes through the request (SELECT MAX(id) FROM s_products)
. And when we click on parsing again, the products are created again, and do not update those that already exist.
Here is the request:

INSERT INTO s_products(url,name,brand_id,meta_title,meta_keywords,meta_description) VALUES ((SELECT MAX(product_id) FROM s_lang_products),'%Название%','0','%Название%','%Название%','%Название%');
INSERT INTO s_products_categories(product_id,category_id,position) VALUES ((SELECT MAX(id) FROM s_products),'24','0');
INSERT INTO s_lang_products(lang_id,product_id,name,meta_title,meta_keywords,meta_description,special) VALUES ('1',(SELECT MAX(id) FROM s_products),'%Название%','%Название%','%Название%','%Название%','NULL');
INSERT INTO s_variants(id,product_id,price) VALUES ((SELECT MAX(id) FROM s_products),(SELECT MAX(id) FROM s_products),(SELECT MAX(id) FROM s_products));
INSERT INTO s_options(product_id,feature_id,lang_id,value) VALUES ((SELECT MAX(id) FROM s_products),'5','1','%Назначение%');
INSERT INTO s_options(product_id,feature_id,lang_id,value) VALUES ((SELECT MAX(id) FROM s_products),'6','1','%Сезон%');
INSERT INTO s_options(product_id,feature_id,lang_id,value) VALUES ((SELECT MAX(id) FROM s_products),'7','1','%Ширина профиля%');
INSERT INTO s_options(product_id,feature_id,lang_id,value) VALUES ((SELECT MAX(id) FROM s_products),'8','1','%Серия (высота профиля)%');
INSERT INTO s_options(product_id,feature_id,lang_id,value) VALUES ((SELECT MAX(id) FROM s_products),'9','1','%Посадочный диаметр%');

1 query adds a product
Don't throw any comments, I'm not very strong in sql, but if I replace INSERT with UPDATE it throws an error.
Tell me how to make it so that when a product is requested, if there is one, it only updates it, and if not, it adds it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Tsvetkov, 2018-01-29
@yellow79

https://dev.mysql.com/doc/refman/5.7/en/insert-on-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question