Jump to content

Recommended Posts

Коллеги, приветствую!

Пишу для себя страничку, на которой можно будет задавать акцию на все товары одного производителя, либо товары, определенной категории.

В SQL не скажу, что шибко шарю, накидал вот такой запрос, который должен добавить в oc_product_special все продукты, где производитель Casio

INSERT INTO oc_product_special (product_id, customer_group_id, priority, price, date_start, date_end)
  VALUES (SELECT `product_id` FROM  `wp_product` WHERE `manufacturer_id` NOT IN
  (SELECT `manufacturer_id` FROM  `wp_manufacturer` WHERE  `name` =  'Casio')
AND  `status` =1, 1, 1, 5136, '2015-10-16', '2015-10-31');

Но SQL выдает ошибку 

 

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT `product_id` FROM `wp_product` WHERE `manufacturer_id` NOT IN (SELECT' at line 2

 

Отдельно, вот эта выгрузка по SELECT работает

SELECT `product_id` FROM  `wp_product` WHERE `manufacturer_id` NOT IN
  (SELECT `manufacturer_id` FROM  `wp_manufacturer` WHERE  `name` =  'Casio')
AND  `status` =1

Подскажите, что делаю не так. 

Share this post


Link to post
Share on other sites

Поменял запрос на 

INSERT INTO wp_product_special (product_id, customer_group_id, priority, price, date_start, date_end)
  VALUES ((SELECT `product_id` FROM  `wp_product` WHERE `manufacturer_id` IN
  (SELECT `manufacturer_id` FROM  `wp_manufacturer` WHERE  `name` =  'Casio')
AND  `status` =1), 1, 1, 5136, '2015-10-16', '2015-10-31');

Получаю #1242 - Subquery returns more than 1 row

Share this post


Link to post
Share on other sites

Как я понимаю, если я в customer_group_id, priority, price, date_start, date_end вставлю массивы, то запрос должен будет пройти корректно?

Share this post


Link to post
Share on other sites


INSERT INTO oc_product_special (1_field, 2_field, ...)

SELECT 1_field, 2_field, ...

FROM `wp_product`

WHERE `manufacturer_id` = 'ID'

Edited by timedontwait

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.