Im trying to write an SQL query that will check in the table ‘persons’ in the column ‘rName’ for say a name “jack” and if it exists then UPDATE that row else INSERT a new row with the new rName.
I’v been trying out IF/ELSE statements but haven’t really seen how they work. Or is there a better way to do what I want without If/ELSE? (I haven’t done much of this SQL work, I used to only do UPDATE, INSERT, DELETE, ALTER… that kinda of stuff.
I have this so far: (if jack is found in the rName row then UPDATE it, else INSERT new row)
SELECT * FROM persons IF 'jack' == rName BEGIN [UPDATE Statement] END ELSE BEGIN [ INSERT Statement] END
Edit: I don’t think I quite explained what I wanted, rName should all be unique names, no 2 should be the same. I’v tried ON DUPLICATE KEY UPDATE, but it seems to just inserts a new row with the new data. But I want it to update the already existing rName (jack) row with the new data, the rName (jack) should stay the same but other fields in that row should be updated to the new data provided.