Reputation: 19
I would like to retrieve random data from a column however skip if empty. I tried everything i found here but no luck
$sql = 'SELECT video FROM data ORDER BY RAND() LIMIT 1';
I also read that Order By Rand is slow when you have huge database, if true what is the alternative
Thank you in advance
Upvotes: 0
Views: 91
Reputation: 6202
$sql = 'SELECT video FROM data WHERE video !="" ORDER BY RAND() LIMIT 1';
Or now that I think about it, I really prefer:
$sql = 'SELECT video FROM data WHERE LENGTH(TRIM(video)) > 0 ORDER BY RAND() LIMIT 1';
Upvotes: 1