Trying to do the following: if current row's column c1 is equal to previous row's c1, set column c3 to previous row's column c2; otherwise, set c3 to NULL (or just don't set it to anything). Can someone tell me why the following query results in c3 being null for every row?
The dummy columns are just there to be able to set the variables @c1 and @c2, which are supposed to store this row's c1 and c2 values to be used for the next row. BTW, am I wrong in assuming that c3 will be updated first, i.e. it will get the previous value of @c2 (before @c2 gets assigned to the current c2)?
UPDATE t SET c3 = IF (c1 = @c1, @c2, NULL), dummy1 = @c1:=c1, dummy2 = @c2:=c2;