Say I have table with two columns: Name, Age.
I want to design a query that will return the names and ages sorted by age, but to also have an additional column which will run from 1 to N (the last row).
So for a table with the following rows:
John, 28 Jim, 30 Mike, 28
The following rows will be returned
John, 28, 1 Mike, 28, 2 Jim, 30, 3
How can I do this? (I’m using MySQL, btw, if it makes a diff).
In mysql you can:
However , this next approach is generic (but you need to have unique values in one of the columns of the table , in this example I’ve used name but it could be any unique column)