In a table like this:
ID | user_ID | name | value
1 | 36 | order | {1, 'asc'}
2 | 36 | colvis | 0,1,2,4,7
3 | 36 | colorder | 0,1,2,4,3,5,6,7
4 | 37 | colvis | 0,1,2,4,5,7
where only ID is unique and AUTO_INCREMENT, I need to INSERT new row for user_ID=36 and colvis='something', if row 'colvis' for that user doesn't exist already, i.e do something like 'INSERT IF NOT EXIST user_ID=x AND name=y ELSE UPDATE' query.
For example, if I have user_ID=36 and name='colorder', it should update row 3, but with user_ID=37 and name='colorder' it should insert new row. Same with user_ID=36 and name='filter', it should insert a new row.
It can be done with
$exist = $sql->Query("SELECT * FROM test WHERE user_ID = 36 AND name='colvis'");
if ($exist) {
//UPDATE
} else {
// INSERT
}
But isn't there a one-liner?
I looked at Insert into a MySQL table or update if exists and MySQL procedure to create or update a row in a table and MySql Insert if not exist two column pair otherwise update, but those are not applicable unless I have 'user_ID' and 'name' columns unique, are they?