Ok, I have a table where I will collect users devices. When a user logs in, I want it to register the device, if it already exists, it would just want to update the timestamp. This is only when a user logs in.
The table looks like this:
device_id => BIGINT AUTOINCREMENT PRIMARY KEY
user_id => BIGINT FOREIGN KEY users(id)
device_name => VARCHAR(40) (Will be like 'Donald ducks iphone')
device_type => VARCHAR(10) (Will be defined by the client, like "IOS")
last_usage => TIMESTAMP (On update, new timestamp and all that)
So, when a user logs in, I have the user_id, device_name, device_type.
What I want: if the id, name and type already exists in a row, just update timestamp, else insert the values.
Since this has nothing to do with the primary key I dont know how to do this. Of course I could do something like first select these values, return that and do the update/insert afterwards, but this does not feel right :)