Well, there is a way to do it in a single query, but it takes a long time to run even on a moderate amount of posts and topics, so it's probably best to just script it.

Couple ways to go about it. But, what you're probably going to need to do is just check one topic at a time. So, in your script, just select all of your topic ids, then loop through those and query the posts with that topic id, checking if those keywords exist, with a like '%keyword%' clause. If the posts in that topic don't contain the keywords, then you'd delete the topic from the topics table, and then all of the posts from the posts table with that topic id. No need for a join or anything fancy.

If you need more details, let me know.