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
Assuming you just want to show the row number with your query, then use something like this:
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:
And here is the Fiddle.
But you really should reconsider this approach.
Good luck.