Megandi
Megandi

Reputation: 104

Query Update row with data from another row in the same table

I have table like this... with 3000+ records..

╔═════╦════════╦═════════════╗
║ 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? 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..

Upvotes: 0

Views: 97

Answers (1)

Klaus Byskov Pedersen
Klaus Byskov Pedersen

Reputation: 120927

It's as simple as:

update yourtable set parent_id = id

Upvotes: 2

Related Questions