I had a question yesterday about ordering a mysql query by rand(). And I got a good answer here: https://stackoverflow.com/a/16597706/2333744
THe code for the answer is below.
create temporary table results as
(Select *, @rn := @rn + 1 as rn, rand() as therand
from table1 inner join
table2
on table1.in = table2.in cross join
(select @rn := 0) const
where table1.T = A
);
select *
from results
where therand < 1000/@rn
order by therand
limit 500;
I understand everything except for
cross join (select @rn : = 0) const
I'm not sure what this is doing and if its important. When I remove it I get no performance change. Can anyone understand this part?