Forum Moderators: open

Message Too Old, No Replies

How to Delete All But a Few Categories in Large MySQL Table

Probably a simple thing...but I'm stumped

         

jimh009

7:56 pm on May 7, 2009 (gmt 0)

10+ Year Member



Hello,

I'm far from the greatest of MySQL programmers (read, "dangerous beginner"), but I do use it for simple things. However, I have a problem that I don't know how to solve. Hoping someone might give me a hint.

I have a table full of information that I do NOT need. There are probably well over 1000 categories (which is in it's own column) in this table. What I need to do is to delete everything in this table except for the handful of categories I specifically want.

I know the query to use to delete specific categories. Thus, for another table, I use a query like this:

DELETE FROM 'TABLE' WHERE category IN
('510302',
'260404',
'510901');

But that query won't work with my current problem since I essentially want to delete everything in the table except for a few specific categories. Basically, I want to pick-out (and specifically name) 5-10 categories from this table and nuke everything else, permanently.

Any ideas on what query to use?

Thanks

Jim

Frank_Rizzo

8:04 pm on May 7, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do the opposite:

DELETE FROM 'TABLE' WHERE category NOT IN
('510302',
'260404',
'510901');

Don't forget to make a full backup first - just in case.

jimh009

9:18 pm on May 7, 2009 (gmt 0)

10+ Year Member



Thanks Frank, I knew it had to be something silly and simple like that.

Jim