Is there an elegant w开发者_开发技巧ay to delete all non-selected entries from a table after selecting from it?
I think you mean DELETE
and not DROP
. DROP
can only erase an entire object (e.g., TABLE). If you aren't worried about performance, you can have something like
DELETE FROM mytable WHERE mytable_key NOT IN
(SELECT mytable_key FROM mytable WHERE some_or_another_condition);
Many DBs allow a JOIN
-type syntax that will probably perform better if you have to do this on a frequent basis.
Scary and generic statement... but this will do from whatever table... I wouldn't think you would actually do to a production table though...
delete from SomeTable where NOT (some condition)
精彩评论