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
  • 29,816
  • 26
  • 86
  • 96
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
  • 195,137
  • 36
  • 275
  • 343
  • 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
  • 18,131
  • 10
  • 32
  • 49
LGE
  • 1