Hmm .. combining a temporary TABLE with REPLACE seems to do the trick.

DROP TABLE IF EXISTS t_tree_insert, _t; CREATE TABLE `t_tree_insert` ( `f_node_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `f_parent_id` INT(10) UNSIGNED NULL DEFAULT '0', `f_name` VARCHAR(200) NOT NULL, `f_sort` FLOAT NULL DEFAULT NULL, PRIMARY KEY (`f_node_id`), UNIQUE INDEX `sort` (`f_parent_id`, `f_sort`), INDEX `f_parent_id` (`f_parent_id`), FULLTEXT INDEX `f_name` (`f_name`) ) COMMENT='test tree move operations' COLLATE='utf8_general_ci' ENGINE=InnoDB AUTO_INCREMENT=0 ; insert into t_tree_insert values (130, 1, 'other array', 1) , (142, 2, 'B06', 1) , (143, 2, 'B2L', 2) , (144, 2, 'B2M', 3) , (200, 2, 'INSERT', 3.5) , (145, 2, 'B2N', 4) , (146, 2, 'B2O', 5) , (150, 3, 'other array', 1) ; select * from t_tree_insert order by f_parent_id, f_sort; set @sort=0; create temporary table _t as select f_node_id, f_parent_id, f_name, (@sort:=@sort+1) as f_sort from t_tree_insert as T where f_parent_id = 2 order by T.f_sort ; select * from _t; replace into t_tree_insert (f_node_id, f_parent_id, f_name, f_sort) select * from _t ; DROP TABLE _t; select * from t_tree_insert order by f_parent_id, f_sort;

t_tree_insert
130 1 other array 1
142 2 B06 1
143 2 B2L 2
144 2 B2M 3
200 2 INSERT 3,5
145 2 B2N 4
146 2 B2O 5
150 3 other array 1

_t

142 2 B06 1
143 2 B2L 2
144 2 B2M 3
200 2 INSERT 4
145 2 B2N 5
146 2 B2O 6

t_tree_insert

130 1 other array 1
142 2 B06 1
143 2 B2L 2
144 2 B2M 3
200 2 INSERT 4
145 2 B2N 5
146 2 B2O 6
150 3 other array 1

probably I can even do it without a temp table...

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery


In reply to Re: [OT] MySQL recalibrating a sort-index (replace) by LanX
in thread [OT] MySQL recalibrating a sort-index by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.