使用mysql中的单个更新查询更新具有多个记录的表

时间:2022-03-29 21:06:17

I am retrieving set of records to update the table.

我正在检索一组记录来更新表。

result set look like this,

结果集看起来像这样,

MemId          username             memberName
 -----         -----------          -------------
1              James                James cam                
2              Peter                Peter Parker
3              Allen                Allen Martin
4
.
.
.
n rows

i am getting above result set using select Query. i want to update username with memberName column with single update query.

我使用select Query获得了结果集。我想用单个更新查询更新带有memberName列的用户名。

2 个解决方案

#1


1  

try this

    UPDATE table SET username = memberName 

DEMO HERE

#2


0  

Update goes like this (leave away the WHERE clause if you are sure what you do

更新是这样的(如果你确定你做了什么,请放弃WHERE子句

UPDATE table SET username = memberName WHERE MemId > 4

#1


1  

try this

    UPDATE table SET username = memberName 

DEMO HERE

#2


0  

Update goes like this (leave away the WHERE clause if you are sure what you do

更新是这样的(如果你确定你做了什么,请放弃WHERE子句

UPDATE table SET username = memberName WHERE MemId > 4