MySQL: Update a “sort” column accoreding to ORDER BY
问题 Fully edited: My query has 2 columns from 2 tables: filename and sortorder. Full tables are done here http://sqlfiddle.com/#!9/8c0507 Example: SELECT * FROM table1 t1 LEFT JOIN table2 t2 ON t1.idmd5 = t2.imgid ORDER BY t2.filename WHERE t1.anotherid = "123456"; Output: filename-01.jpg - 12 filename-02.jpg - 73 filename-03.jpg - 1 filename-12.jpg - 63 filename-24.jpg - 99 Now, the "sortorder" column should be re-set according to the ORDER BY - output, it should start at 1. Expected result: