Jump to content
mfleeson

Products without categories

Recommended Posts

Just a silly bit of SQL. I realised that products I had used in previous promotion were not displaying as they were not in any categories, so here's a little bit of SQL to help fix databases if you've been using other tools to administrate your products.

1 - Check for products not in categories.

SELECT * FROM products WHERE products_id NOT IN (SELECT DISTINCT products_id FROM products_to_categories);

2 - If none display then you're fine. If they do then choose a category to put them in and get the category number.  If need be create a new category and look for the number in the database, i.e.

SELECT MAX(categories_id) FROM categories_description;

3 - Move the uncategorised products into your new category... If the previous query resulted in 211 then

INSERT INTO products_to_categories SELECT products_id,211 FROM products WHERE products_id NOT IN (SELECT DISTINCT products_id FROM products_to_categories);

 

Share this post


Link to post
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

×