Question : Getting last_insert_id() in a trigger in Mysql

I am trying to create a trigger that inserts a record into table2 when table1 has a new record inserted.
It seems that last_inserted_id returns nothing as the table2 record is never created. If I hard code a value for last_insert_id it works correctly.

Any pointers please!
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
CREATE TRIGGER `client_tracker`.add_inv AFTER INSERT
 ON brite_supplement
 FOR EACH ROW 
INSERT INTO investments ( client_id, investment_name, investment_date, investment_type, investment_amount )
SELECT brite_supplement.client_id, "27" AS Expr1, brite_supplement.investment_date, brite_supplement.investment_type, brite_supplement.investment_amount
FROM brite_supplement
WHERE brite_supplement.ID=last_insert_id();
Open in New Window Select All

Answer : Getting last_insert_id() in a trigger in Mysql

you use
NEW.id_field

and not last_insert_id()

all the fields, FOR EACH ROW, are available via the NEW virtual record:
http://dev.mysql.com/doc/refman/5.0/en/trigger-syntax.html
Random Solutions  
 
programming4us programming4us