0

i have a table look like this:

table: fruits

------------
num | fruit
------------
1   | apple
1   | banana
2   | orange
2   | apple
2   | guava
3   | grape
3   | strawberry
4   | blueberry
4   | watermelon
4   | honeydew
4   | apple

i want to update the sequence to the number that i choose, example start from 600, i tried something like this:

UPDATE fruits
JOIN (SELECT @rank := 600) r
SET num=@rank:=@rank+1;

it become:

------------
num   | fruit
------------
601   | apple
602   | banana
603   | orange
604   | apple
605   | guava
606   | grape
607   | strawberry
608   | blueberry
609   | watermelon
610   | honeydew
611   | apple

result that i want is:

------------
num   | fruit
------------
621   | apple
621   | banana
622   | orange
622   | apple
622   | guava
623   | grape
623   | strawberry
624   | blueberry
624   | watermelon
624   | honeydew
624   | apple

so that previous num with 1 will become 601 and 2 will become 602. Any idea? thanks

1 Answer 1

1

How about just using +?

UPDATE fruits
    SET num = num + 600;

(In your example, you seem to want + 620 rather than + 600.)

Sign up to request clarification or add additional context in comments.

2 Comments

What if I want to start in some random number like 564, how the sequence going to work?
@Teddybugs . . . You would adjust the 600 to be the appropriate offset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.