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

  • SEARCH
  • Home
  • 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 7965657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:13:10+00:00 2026-06-04T06:13:10+00:00

This is my Table ################################ # id_formfield # ID # int_Sort # ################################ #

  • 0

This is my Table

################################
# id_formfield # ID # int_Sort #
################################
#      1       # 1  #     2    #
#      2       # 1  #     3    #
#      3       # 1  #     4    #
#      4       # 1  #     4    #
#      5       # 1  #     4    #
#      6       # 2  #     1    #
#      7       # 2  #     3    #
#      8       # 2  #     3    #
#      9       # 2  #     4    #

As you can see my int_sort column is messed up somehow with equal numbers and I wanna to make it sequence with row number and reset row number when ID changes.
this should be result:

############################################
# id_formfield # ID # int_Sort # rownumber #
############################################
#      1       # 1  #     2    #     1     #
#      2       # 1  #     3    #     2     #
#      3       # 1  #     4    #     3     #
#      4       # 1  #     4    #     4     #
#      5       # 1  #     4    #     5     #
#      6       # 2  #     1    #     1     #
#      7       # 2  #     3    #     2     #
#      8       # 2  #     3    #     3     #
#      9       # 2  #     4    #     4     #

Edit : id_formfield is my primary key and order by int_sort ascending

  • 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-04T06:13:11+00:00Added an answer on June 4, 2026 at 6:13 am

    Following script should get you started. In a nutshell, the script

    • creates a temp table, adding an IDENTITY column to serve as rownumber
    • inserts your original data into the temp table
    • uses MIN(Rownumber) for each ID to get an offset.
    • JOIN the temp table with the calculated offsets to restart the count for each group.

    SQL Statement

    CREATE TABLE #TempTable (Rownumber INTEGER IDENTITY(1, 1), ID INTEGER)
    SET IDENTITY_INSERT #TempTable OFF
    
    INSERT INTO #TempTable
    SELECT      *
    FROM        YourOriginalTable
    ORDER BY    ID, int_Sort
    
    SELECT    t.ID, t.Rownumber, t.Rownumber - o.Offset
    FROM      #TempTable t
              INNER JOIN (
                SELECT    ID, MIN(Rownumber) - 1 AS Offset
                FROM      #TempTable
                GROUP BY  ID
              ) o ON o.ID = t.ID            
    
    
    DROP TABLE #TempTable
    

    Test script

    DECLARE @YourTable TABLE (ID VARCHAR(1))
    CREATE TABLE #TempTable (Rownumber INTEGER IDENTITY(1, 1), ID INTEGER)
    
    SET IDENTITY_INSERT #TempTable OFF
    INSERT INTO @YourTable (ID) VALUES (1)
    INSERT INTO @YourTable (ID) VALUES (1)
    INSERT INTO @YourTable (ID) VALUES (1)
    INSERT INTO @YourTable (ID) VALUES (1)
    INSERT INTO @YourTable (ID) VALUES (1)
    INSERT INTO @YourTable (ID) VALUES (2)
    INSERT INTO @YourTable (ID) VALUES (2)
    INSERT INTO @YourTable (ID) VALUES (2)
    INSERT INTO @YourTable (ID) VALUES (2)
    
    INSERT INTO #TempTable
    SELECT      *
    FROM        @YourTable
    ORDER BY    ID
    
    SELECT    t.ID, t.Rownumber, t.Rownumber - o.Offset
    FROM      #TempTable t
              INNER JOIN (
                SELECT    ID, MIN(Rownumber) - 1 AS Offset
                FROM      #TempTable
                GROUP BY  ID
              ) o ON o.ID = t.ID            
    
    
    DROP TABLE #TempTable
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this table: ID(INT) DATE(DATETIME) Under the DATE column there are a lot
I have a table with misc. data. Each row has a checkbox. This table
I have this table: id (int) name (varchar) insert (timestamp) An example row is
I have a table with a column like this that is currently live: name
I have this table: id feed_id ... Let's say that I have 500 rows
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID
This table is used to store sessions (events): CREATE TABLE session ( id int(11)
I have this table: User id INT PK login VARCHAR UNIQUE I want to
I have two table like this table_CN (_id, name, phone, favorite, title) table_EN (_id,
I have this table: fourn_category (id , sub) I am using this code to

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.