左连接但是取随机值

时间:2017-07-07 16:30:43

标签: mysql sql

学习SQL。加入两个表后如何随机抽取样本?非常感谢。

select  *
from t1 
left join t2  on t1.ID = t2.ID

1 个答案:

答案 0 :(得分:2)

只需添加ORDER BY rand()LIMIT样本大小(例如5):

select  *
from t1 
left join t2  on t1.ID = t2.ID
ORDER BY rand()
LIMIT 5