I have two tables, one for storing reports of a user, and another for storing users.
1. Report_table
-----report_id(P)-----user_id--------
001 user1
002 user1
003 user3
2.Users table
-------user_id(P)-------no_of_reports
user1 2
user2 0
user3 1
Now whenever a report is inserted in report_table(say report_id:004, user_id: user1), I update both tables like this.
INSERT INTO reports_table VALUES (004,`user1`)
INSERT INTO users_table (user_id,no_of_reports) VALUES (`user1`,1)
ON DUPLICATE KEY UPDATE no_of_reports=no_of_reports+1;
Is there a better way of doing this.. Is there a way of automatically incrementing the no_of_reports counter when a new report is inserted?