简体   繁体   English

使用同一表中另一行的数据查询更新行

[英]Query Update row with data from another row in the same table

I have table like this... with 3000+ records.. 我有这样的表...有3000多个记录..

╔═════╦════════╦═════════════╗
║ id  ║  text  ║  parent_id  ║
╠═════╬════════╬═════════════╣
║   1 ║  asas  ║           0 ║
║   2 ║  fgh   ║           0 ║
║   3 ║  jkl   ║           0 ║
║   4 ║  kkk   ║           0 ║
║   5 ║  test  ║           0 ║
║   6 ║  asd   ║           0 ║
║   7 ║  dsa   ║           0 ║
╚═════╩════════╩═════════════╝

how to change the parent_id value to same like id? 如何将parent_id值更改为与id相同? to like this... 喜欢这个...

╔═════╦════════╦═════════════╗
║ id  ║  text  ║  parent_id  ║
╠═════╬════════╬═════════════╣
║   1 ║  asas  ║           1 ║
║   2 ║  fgh   ║           2 ║
║   3 ║  jkl   ║           3 ║
║   4 ║  kkk   ║           4 ║
║   5 ║  test  ║           5 ║
║   6 ║  asd   ║           6 ║
║   7 ║  dsa   ║           7 ║
╚═════╩════════╩═════════════╝

and more..... until 3000+records.. 以及更多.....直到3000多个记录

就像这样简单:

update yourtable set parent_id = id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更新从同一个表中的另一行获取的现有行中的数据 - Update data in an existing row taken from another row in the same table 使用同一表中另一行的数据更新行 - Update row with data from another row in the same table 使用同一表中另一行的数据更新行 - Update a row with data from another row within the same table 使用 sqlalchemy 查询在同一表中包含另一行的数据 - Include data from another row in in the same table with sqlalchemy query 从同一表的另一行更新表行 - update table row from another row same table 基于相似字段,使用同一表中另一行的数据更新一行 - Update a row with data from another row in the same table based on a similar field SQL QUERY在一行中多次搜索以从同一表的另一行中查找数据 - SQL QUERY multiple search in one row to find data from another row in the same table 使用来自不同表中另一行的数据更新单行或多行 - Update single or multiple row with data from another row in the different table MySQL:使用另一个表中的值在一个查询中多次更新同一行 - MySQL: Update same row multiple times in one query with values from another table 有没有办法将 SQL 中的查询中的某些数据批量插入到同一个表中具有相同行的另一列? - Is there a way to bulk insert certain data from a query in SQL to another column with the same row within the same table?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM