找回密码
 快速注册
搜索
查看: 36|回复: 0

MySql交换表的两行

[复制链接]

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2022-10-25 03:25 |阅读模式
本帖最后由 hbghlyj 于 2022-10-26 19:06 编辑 MySql取出tid为210和280的两行, 把它们的fid和subject交换
  1. update `forum_thread` a
  2. inner join `forum_thread` b on a.tid <> b.tid
  3.    set a.fid = b.fid,
  4.        a.subject = b.subject
  5. where a.tid in (210,280) and b.tid in (210,280)
复制代码

输出信息
2 rows affected. (Query took 0.0033 seconds.)
参考资料:
Mysql: Swap data for different rows

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 15:44

Powered by Discuz!

× 快速回复 返回顶部 返回列表