SELECT (@row:=@row+1) AS ROW, ID
FROM table1 ,(SELECT @row := 0) r
order by ID desc
How does SQl evaluate this? Strangely, there seems to be little to no literature on this sort of this with variables in the SELECT statement.
- How can SELECT select row = 0? I thought select had to select an entire column
- what is the r here?
- How does the SELECT @row:=@row+1 know how to iterate through the rows?
- Its not clear to me how the ID is set here. The @row surely correspond somehow to the ROW, but ID seems to be just hanging on
- Why does the FROM need to take from more than just the table 1?