Hi All
SET @x = 0;
UPDATE table SET sort_order = (@x:=@x+1) ORDER BY f1, f2;
This sets the sort_order field on record 1 to1, 2 to 2 and so on...
What I need is to reset @x when a new group begins, so GROUP BY field1, ORDER BY field2
What I want is
f1 f2 sort_order
1 3 1
1 4 2
1 7 3
2 1 1
2 5 2
I just can't think of a way to do this with SQL!
Thanks for any ideas
SET @x = 0;
UPDATE table SET sort_order = (@x:=@x+1) ORDER BY f1, f2;
This sets the sort_order field on record 1 to1, 2 to 2 and so on...
What I need is to reset @x when a new group begins, so GROUP BY field1, ORDER BY field2
What I want is
f1 f2 sort_order
1 3 1
1 4 2
1 7 3
2 1 1
2 5 2
I just can't think of a way to do this with SQL!
Thanks for any ideas