MySql insert trigger outputs NULL
<p>I want to have an insert trigger to achieve incremental inserts. I have one column "row_hash" to record the MD5 of each row(here I use MD5 of column <code>name</code> and <code>category</code>). If the new record has the same hash value, the trigger should skip insert, otherwise it allows the insert. </p>

<pre><code>DROP TRIGGER IF EXISTS test_trigger;
DELIMITER $$
CREATE TRIGGER test_trigger BEFORE INSERT ON test_table FOR EACH ROW
BEGIN
    IF (SELECT COUNT(*) FROM test_table WHERE row_hash = MD5(CONCAT_WS('', new.name, new.category))) &lt; 1 THEN
        INSERT INTO test_table(_id, name, category, row_hash) VALUES (new._id, new.name, new.category, MD5(CONCAT_WS('', new.name, new.category)));
    END IF;
END$$
</code></pre>

<p>Here is the test table:</p>

<pre><code>create table test_table(_id varchar(10) primary key, name varchar(10), category varchar(2), row_hash char(32));
</code></pre>

<p>When I insert one record, it outputs NULL on the <code>row_hash</code> column.</p>

<pre><code>insert into test_table(_id, name, category) values('12344', 'dafas', 'A');

'12344','dafas','A',NULL
</code></pre>

<p>Can you tell me where I did it wrong on the trigger?</p>