newbieguy newbieguy - 3 months ago 10
SQL Question

How to update 1 row only in SQLite

I have a table ,for example,

members
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
Luke
in the table?

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

Answer

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.

Comments