I have a table that captures a bunch of information whenever a user logs into my app. Three of the main fields are username, ip, and datetime. I created a new table (user_ip_table) which has the following columns.
ID (unique auto gen)
I want to create a trigger on the main table to keep track of the last ip address used by a given user. So when a new row is inserted into the main table the trigger will fire and do one of the following.
if username/ip combo is present in user_ip_table then do nothing
if username is present but with a different ip then update the ip address and datetime
if username is not present then insert it with ip and datetime
Is there an easy way to do this? Or do I need to create 3 triggers, one for each case?