We help IT Professionals succeed at work.

Delete all rows in SQL except 4?

OMDBot
OMDBot asked
on
Hi,

I am using phpMyAdmin and would like to delete all rows in a 5000+ row table with the exception of the top four rows (ID 1 2 3 and 4)

Is there any simple SQL code which can delete all rows except the ID's specified?
Comment
Watch Question

Data Warehouse / Database Architect
Commented:

Piece of cake.  :)

DELETE FROM mytable WHERE id not in (1, 2, 3, 4);


Good Luck,
Kent

Author

Commented:
Perfect! Thanks!