Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update only one row in a table?

How to I can update only one record in a table?

Table:

name       name1       name2 ---------------------------- xx         xy          xz xx         xx          xx xx         xx          xx xx         xx          xx xy         xx          zz 

Update query:

UPDATE table1  SET name2 = '01'  WHERE name1='xx' 

I need update only one row per time.

like image 520
Klapsius Avatar asked Nov 14 '14 11:11

Klapsius


People also ask

Which command is used to UPDATE rows in a table?

UPDATE MySQL command is used to modify rows in a table. The update command can be used to update a single field or multiple fields at the same time.


1 Answers

you can use ROWCOUNT

SET ROWCOUNT 1  UPDATE table1  SET name2 = '01'  WHERE name1='xx'  SET ROWCOUNT 0 

or you can use update top

UPDATE TOP (1) table1  SET name2 = '01'  WHERE name1='xx' 
like image 159
s_f Avatar answered Oct 07 '22 17:10

s_f