Iam looking for best algorithm to do this query using mysql.
SELECT room_no,fname,lname,title,gender,age,text
FROM travelers WHERE reservation_id='9911'
ORDER BY joinnum ASC, id ASC
Result
room_no
1 infant tess Mr M 0
1 infant2 te1ss Mr M 0
2 tes3 test66 Mr M 0
2 tes3 test Mr M 0
2 ss33 test66 Mr M 0
I want to add another column using sql capabilities which give me an index for each traveler depending on room_no for example
traveler_order room_no
0 1 infant tess Mr M 0
1 1 infant2 te1ss Mr M 0
0 2 tes3 test66 Mr M 0
1 2 tes3 test Mr M 0
2 2 ss33 test66 Mr M 0
Which mean give an index foreach row according to the room i.e. room 1 has 2 traveler the select statment will give an index 0 for row 0 and 1 for row 1 but row 2 start new room therefore it will give row 2 index 0 the 1 the 2 ... etc. I hope to help me to solve this problem.
More description
What i need is give an order foreach traveler according to the room number for example room 1 have 2 travelers therefore row 1(traveler 1 ) will take index 0 the traveler 2 will take (index 1) then start in room 2 have (3 travelers ) the order will be traveler 1 in room two take index 0 and traveler 2 in room 2 will take index 1 and traveler 3 in room 2 will take index 2 like the second table above