Issue
i would like to create a trigger using the phpmyadmin "add trigger" option. The Trigger should run AFTER every INSERT in table comments that takes the highest "number of comments" (nc in DB) from the table "POST" and takes the "ID" and the "question" of that row and puts it in the "top_questions" table
Update1: i want the top 5 records with the 5 highest "number of comments" sorted descendingly to be put into the table Top Questions
Post Table: post table
Top Questions Table:top_questions table
MCO stands for "most commented on" and that's where the question needs to be taken from post and put in
Comment Table: comment table
update2: at this point i'm wondering should i make it as a trigger, view, or materialized view? (i would still prefer it as a trigger)
Solution
you can put it by selecting after insert command
BEGIN
INSERT INTO top_question(MCO,PID)
SELECT ID,P_ID FROM `comment_tbl` GROUP BY P_ID order by COUNT(*) DESC LIMIT 10
END
just put this lines in phpmyadmin in trigger (select after insret in commaent table )
Answered By - kiamoz
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.