newbieguy newbieguy - 1 year ago 41
SQL Question

How to update 1 row only in SQLite

I have a table ,for example,

and these is its data

Id first_name gender
1 Alexis Female
2 Luke Male
3 Jireh Male
4 Luke Male

How do I update the first
in the table?

UPDATE members SET first_name='Eduard' WHERE first_name='Luke'
changes both Luke

Answer Source

You should UPDATE on the Id column rather than on FirstName in the WHERE clause. As shown below.

UPDATE members
SET first_name = 'Eduard'
WHERE Id = 2

The benefits of doing it by ID is that you know the exact row you are updating rather than assuming the member you are attempting to update is the correct one.