I have 2 tables 1st table word_cloud (auto inc), predefined_text, content_id . 2nd table word_cloud_count (auto inc),predefined_text,content_id,count . I am calling a trigger when data is inserted into word_cloud, which basically groups the word, calculates the count and inserts it into word_cloud_count
word_cloud table consists of
id | predefined_text | content_id
---------------------------------
1 | ABC | 1
2 | ABC | 1
3 | ABC | 1
4 | XYZ | 2
5 | XYZ | 2
6 | XYZ | 2
7 | XYZ | 1
8 | ABC | 2
9 | ABC | 2
10 | ABC | 2
word_cloud_count consists of
id | predefined_text | content_id | count
-----------------------------------------------
1 | ABC | 1 | 3
2 | XYZ | 2 | 3
3 | ABC | 2 | 3
4 | XYZ | 1 | 1
Trigger Function
CREATE TRIGGER word_cloud_count_insert after insert on word_cloud
INSERT INTO word_cloud_count (Word,content_id ,count )
SELECT predefined_text,content_id, count(*)
FROM word_cloud
group by predefined_text,content_id
Everything works fine and the values are being inserted in the word_cloud_count table
However my problem is every time the data is inserted into word_cloud the trigger is called and duplicate values are being stored into word_cloud_count
How do i avoid this
Any suggestions would be of great Help, Thanks in advance