A9300G1
A9300G1

Reputation: 13

Mysql update with counter

Whenever i try to run this query

UPDATE AddItem SET IUID=IUID+1 WHERE UID=1

I am expecting to see an incremental number

1    
2    
3

But what i actually get is

1    
1    
1

Upvotes: 1

Views: 1958

Answers (1)

Juan Carlos Oropeza
Juan Carlos Oropeza

Reputation: 48197

Use variables. SQL DEMO

update AddItem
cross join (SELECT @id := 0 ) as a
set id = @id := @id + 1
where id =1;

Upvotes: 1

Related Questions