EdgeCase
EdgeCase

Reputation: 4827

Can this MySQL Be Run in JDBC?

I am tasked with keeping a sequence number in a table sequential for a certain product ID. Apart from the argument over whether this is a good thing (I lost the argument), can this SQL statement be run in JDBC? Actually, I guess there are two statements here. We are using Spring JDBCTemplates.

SET @rank:=0; 

UPDATE my_table
SET product_set=@rank:=@rank+1 
WHERE product_id = '123456'; 

Upvotes: 0

Views: 53

Answers (1)

juergen d
juergen d

Reputation: 204784

you can define a variable inside your query like this

UPDATE my_table
inner join (select @rank:= 0) r
SET product_set = @rank:=@rank+1 
WHERE product_id = '123456'; 

Upvotes: 1

Related Questions