Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7790453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:35:32+00:00 2026-06-01T21:35:32+00:00

I have a table with an integer field that is used to control the

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:35:34+00:00Added an answer on June 1, 2026 at 9:35 pm

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a table 'test' I have an integer field TestID, with an index. SELECT
In a specific table I have a SortOrder integer field that tells my page
I have a table with an integer field. I want to select all rows
Say I have a table with a unique positive integer field. I currently have
I have a table that contains intervals: CREATE TABLE tbl ( user_id: INTEGER, start:
I have a table that's created like this: CREATE TABLE bin_test (id INTEGER PRIMARY
Assuming I have a table with one field called ID that stores 100 different
I have to constantly sort a table by a field that has a decimal
I have a table defined by: CREATE TABLE bar_table ( _id INTEGER NOT NULL
I have the following table: Tweet(id: integer, from_user: string, tweet_text: string, tweet_id: integer, course_id:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.