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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:09:08+00:00 2026-06-18T06:09:08+00:00

I have a 5 column table (columns are id , answer, weight, quiz_id and

  • 0

I have a 5 column table (columns are id , answer, weight, quiz_id and question_id)
and I would like to sort it by question_id, then sort by weihgt, then I would like to renumber the id column incrementally according to this double sorting.
Is it possible in mysql (I am using phpmyadmin)?

thanks

something like:

SELECT 
   @curRow := @curRow + 1 AS id,
   T.Answer, T.Weight, T.Quiz_Id, T.Question_Id
FROM wp_wpss_Answers T
   JOIN    (SELECT @curRow := 0) r
ORDER BY QuestioN_Id, Weight
LIMIT 0 , 1000
  • 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-18T06:09:09+00:00Added an answer on June 18, 2026 at 6:09 am

    Assuming you just want to show the row number with your query, then use something like this:

    SELECT 
       @curRow := @curRow + 1 AS RowNumber,
       T.Answer, T.Weight, T.Quiz_Id, T.Question_Id, T.Id
    FROM YourTable T
       JOIN    (SELECT @curRow := 0) r
    ORDER BY QuestioN_Id, Weight
    

    If you’re wanting to update your ID, you can use the above, but I’d ask why are you doing this? I can’t see any reason to renumber your ID columns — set it to an Identity and let MySQL handle it.

    However, to update your Id column, try something like this:

    UPDATE YourTable t
      JOIN (SELECT 
           @curRow := @curRow + 1 AS RowNumber,
           T.Answer, T.Weight, T.Quiz_Id, T.Question_Id, T.Id
        FROM YourTable T
           JOIN    (SELECT @curRow := 0) r
        ORDER BY QuestioN_Id, Weight) T2 ON T.Id = T2.Id
    SET t.Id = T2.RowNumber
    

    And here is the Fiddle.

    But you really should reconsider this approach.

    Good luck.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a column in an org mode table that is
I have a table with columns id, user I want to group by column
I have a DataGrid table with columns name , phone . In column name
I have a table with two columns: column A column B 1 2 1
I have a table with few columns and one of the column is DockNumber.
I have a table with 4 columns. The first column is unique for each
I have a mysql table that has 2 columns - Column 1 contains a
I have a table called scheduler_sched which has several columns, including a column called
I have two tables with similar columns - let's say table A with column
I have a DataGridView bound to xml file. I would like to sort by

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.