[英]Query Update row with data from another row in the same table
我有這樣的表...有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 ║
╚═════╩════════╩═════════════╝
如何將parent_id值更改為與id相同? 喜歡這個...
╔═════╦════════╦═════════════╗
║ 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 ║
╚═════╩════════╩═════════════╝
以及更多.....直到3000多個記錄
就像這樣簡單:
update yourtable set parent_id = id
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.