DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id int(11) unsigned not null AUTO_INCREMENT, f1 VARCHAR(10), f2 VARCHAR(10),
   PRIMARY KEY(id)
);
INSERT INTO t1 (f1,f2) VALUES ('1','2'), ('2','2'), ('3','2'), ('4','2'), ('5','2');

/*I would request records where the 'f2' column value not equal previous row's 'f2' column value.*/

/* If I use ORDER BY the result set is bad. All record present in the result set. */
SELECT @beforval, f2, id,@beforval:=f2 AS setvalue,f1,f2 FROM t1,
(select @beforval:='') as init
WHERE
   @beforval<>f2 
ORDER BY f2 DESC;

/* If I not use ORDER BY the result set is correct. Same query without ORDER BY. The result set is contains one row. */
SELECT @beforval,  f2, id,@beforval:=f2 AS setvalue,f1,f2 FROM t1,
(select @beforval:='') as init
WHERE
   @beforval<>f2;

