0

I have Post HABTM Tags (tables: posts, tags, posts_tags).

When I delete Post also deleting relations from post_tags table - it's okey, but in table tags there are still not used tags.

How resolved remove not uset tags?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
kicaj
  • 2,881
  • 5
  • 42
  • 68

1 Answers1

0

Okey, I found the simplest way: https://stackoverflow.com/a/1451323/182823:

DELETE FROM tags WHERE not exists (SELECT * FROM tags_places WHERE tags_places.tag_id = tags.id)
Community
  • 1
  • 1
kicaj
  • 2,881
  • 5
  • 42
  • 68