I have 2 tables.
I use this query to find the number of occurences of a field from one table in another table
select t.id, t.tag_text, count(*) cnt from sms s, template as t
group by t.tag_text
order by cnt desc
delete from template where id in ( select id_template from sms group by id_template having count(*) < 5 )