Jump to content

Question about sql query


Recommended Posts

Hello. I have been importing products from csv-file without categories.

Now I'm fiddling around and have this situation: som products (lets say id 15,16,17) have got category, but all have position 0.

Actually there are bigger amount.

I found a query to alter the position semi-manually:

UPDATE ps_category_product INNER JOIN (SELECT id_product FROM ps_category_product WHERE id_product in(15,16,17) and position = 0 LIMIT 1) as t2 using(id_product) SET position = 1;

This is a way where the updates are limited to one row.

But I wanted to make it more automatic and tried:

UPDATE ps_category_product INNER JOIN (SELECT id_product FROM ps_category_product WHERE id_product in(15,16,17) and position = 0 LIMIT 1) as t2 using(id_product) SET position = SELECT MAX(position)+1 FROM ps_category_product as t3 WHERE id_product IN (15,16,17);

But it doesn't work, even though the query

SELECT MAX(position)+1 FROM ps_category_product as t3 WHERE id_product IN (15,16,17);

works.

I wonder why.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...