There may be some business requirements that needs to retrieve only some rows from a table (or join tables) randomly. This kind of SQL is normally hard to tune.
For example the following SQL retrieve one row from two tables join of Employee and Department, where Employee’s department code is ‘AAA’, and both Emp_dept and Dpt_id columns are indexed.
select *
from employee ,department
where emp_dept=dpt_id
and emp_dept = 'AAA'
order by rand()
limit 1
Here the following is the query...
How to tune “order by rand() limit 1” SQL statement ?
For example the following SQL retrieve one row from two tables join of Employee and Department, where Employee’s department code is ‘AAA’, and both Emp_dept and Dpt_id columns are indexed.
select *
from employee ,department
where emp_dept=dpt_id
and emp_dept = 'AAA'
order by rand()
limit 1
Here the following is the query...
How to tune “order by rand() limit 1” SQL statement ?