I have a database table for users, and it has a column gcm_id
for push notifications to android.
I set this column to be unique since a user might logout and login on the same device so they will have the same gcm_id.
I want the behaviour to be as followed:
When an update for a user's gcm_id
column is request, if the specific gcm_id
already exists, change it to null and continue to update as usuall on the request row.
I'll give an example. Say I have the following entries in my table:
index | user_name | gcm_id
------+-----------+-------
1 | Tom | 123
2 | John | NULL
If Tom logs out and logs in as John, the client will want to update the gcm_id for John to be 123
. But gcm_id
column should be unique. So in that case, I would like that the mysql server will change Tom's gcm_id
to NULL
and set John's gcm_id
to be 123
.
All I've seen so far in relation to ON DUPLICATE
syntax is to make mysql update only the existing row instead of creating a new one. I want to do both.
Is that possible in a single mysql command?