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 221993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:05:08+00:00 2026-05-11T19:05:08+00:00

I have the following table Id Value 1 3 1 12 1 67 2

  • 0

I have the following table

Id   Value
1     3
1     12
1     67
2     7
2     99
5     30
5     33
5     4
5     87
5     12
5     1

I’d like to update it to have this table.

Id  UniqueIdBySubSet    Value
1           1             3
1           2             12
1           3             67
2           1             7
2           2             99
5           1             30
5           2             33
5           3             4
5           4             87
5           5             12
5           6             1

I found the perfect thread on SO, but it was for mssql. I use mysql 4.1.10.

The other thread can be found here: Generating sequences for subsets of a table.

Does anyone knows how I can do that in mysql ?

Thank you,
Jean-Francois

  • 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-05-11T19:05:08+00:00Added an answer on May 11, 2026 at 7:05 pm
    SET  @r := 0;
    SET  @id := 0;
    UPDATE  mytable m
    SET     m.UniqueIdBySubSet = IF(@id = id, @r := @r + 1, @r := (@id := id) - id)
    ORDER BY
            id, value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks like the following: ID Key Value Order 1
I have the following query in VBA: DoCmd.RunSQL INSERT INTO table (value) VALUES ('example')
Assume I have the following style table, col1 col2 and col3 have same value
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
I have a following mysql table with a lot (3000+) of values: [id] [parent_id]
I have a simple table like following: class SnookerCurrentInfo extends Doctrine_Record { public function
I have the following html: <style type=text/css> .message-view-value-td { vertical-align:bottom; } </style> <table width=600>
I have a table like this Table ----- userid fieldid fieldvalue where userid and
I have the following code using SubSonic 2.1/2.2 SubSonic.Update(<some table>) .Set(<column A>) .EqualTo(<column B>).
I have a (mysql) database table with the following columns: NAME | String (Unique)

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.