Q:

Update table based on row number

I have a table with an integer field that is used to control the custom display order a record.  
Example:
SET @rownumber = 0;

SELECT 
@rownumber:=@rownumber+1 AS rownumber, 
slides.displayorder 
WHERE 
active = 1 
ORDER BY displayorder ASC

This query gives me a result a bit like this:
 rownumber | displayorder
-----------+-------------
     1           2
     2           7 
     3           15
     4           50 
     5           80

This works OK until a record gets deleted / unapproved (hence the gaps in display order).
What I would like to do is run an update query that sets the displayorder column to the value of the rownumber variable after a record is removed.
Giving a result like this:
 rownumber | displayorder
-----------+-------------
     1           1
     2           2 
     3           3
     4           4 
     5           5

Is there an easy way to do this?

A:

This seemed to do the job.
SET @rownumber = 0;
INSERT INTO slides (id, displayorder) 
SELECT a.id, a.rownumber 
FROM (SELECT id, (@rownumber:=@rownumber+1) AS rownumber FROM slides WHERE active = 1 ORDER BY displayorder ASC) AS a ON DUPLICATE KEY UPDATE displayorder = a.rownumber

