I am little bit confused with the usage of trigger event to get expected result
Here main table is fee. The structure is as follow
Fee
id | rn | fid | amount | f_month | year
====================================================
1 | 1 | 1 | 150000 | 1 | 1
2 | 1 | 2 | 50000 | 1 | 1
3 | 2 | 1 | 550500 | 2 | 1
4 | 2 | 2 | 200 | 2 | 1
5 | 3 | 1 | 550500 | 2 | 1
And the simply insert trigger has been used.
DROP TRIGGER IF EXISTS `insertinv`;
CREATE DEFINER=`root`@`localhost` TRIGGER `insertinv`
AFTER INSERT ON `fee` FOR EACH ROW INSERT INTO invoice VALUES(null, NEW.rn, NEW.year, '')
The output what I am getting
Invoice
inv | rn | y_d | status
==============================
1 | 1 | 1 | 0
2 | 1 | 1 | 0
3 | 2 | 1 | 0
4 | 2 | 1 | 0
5 | 3 | 1 | 0
But I want to apply condition
if fee.rn AND fee.f_month AND fee.year is same then stop to insert. I mean ignore the fee.fid.
and achieve following result. The expected one
Invoice
inv | rn | y_d | status
==============================
1 | 1 | 1 | 0
2 | 2 | 1 | 0
3 | 3 | 1 | 0
In trigger table inv is primary key and auto increment