MySQL update a field with an incrementing variable

Simple query would be, just set a variable to some number you want. Then update the column you need by incrementing 1 from that number.

Ex:: Query to update all the rows where a column is null. it'll update each row id by incrementing 1

    SET @a  = 50000835 ;  
    UPDATE `civicrm_contact` SET external_identifier = @a:=@a+1 
    WHERE external_identifier IS NULL;

Are you looking for something like this?

UPDATE textile_events e,
       (SELECT @n := 249) m
   SET e.seq_no = @n := @n + 1 
    WHERE e.eid = 'headsup' AND e.paid = 'paid'

SQLFiddle

Tags:

Mysql