1
SELECT * FROM (SELECT * FROM my_table ORDER by row_id DESC LIMIT 8) t ORDER BY RAND()

I saw this in an answer, What does the 't' mean before ORDER BY?

Machavity
  • 30,841
  • 27
  • 92
  • 100
Pete
  • 53
  • 7
  • Possible duplicate of [Nested select statement in SQL Server](http://stackoverflow.com/questions/4629979/nested-select-statement-in-sql-server) – Aurora0001 Feb 26 '17 at 20:48

2 Answers2

3

Subqueries need an alias name. In this case it is t.

With this name you can refer to the result of the subquery and its columns.

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • 1
    *With this name you can refer to the result of the subquery and its columns.* Also without it. – shmosel Feb 26 '17 at 20:53
0

In order to make the aliasing even clearer, you should use AS and also use accent grave. This re-written query would be easier to read

SELECT * FROM (SELECT * FROM `my_table` ORDER by `row_id` DESC LIMIT 8) AS `t` ORDER BY RAND()
Syscall
  • 19,327
  • 10
  • 37
  • 52
LGE
  • 1