My personel table id colum is 1,2,3, 4,6,7,8,9,12,13,14,15,16,20
How to get random 5 rows and id not in 1,2,6
My personel table has 100K records
My personel table id colum is 1,2,3, 4,6,7,8,9,12,13,14,15,16,20
How to get random 5 rows and id not in 1,2,6
My personel table has 100K records
You could order the table by rand()
and limit
the results:
SELECT id
FROM personel
WHERE id NOT IN (1, 2, 6)
ORDER BY rand()
LIMIT 5
You can filter out the ones you don't need using not in
and order by rand()
function to randomize the order, then limit
rows to 5.
select * from table
where id not in (1,2,6)
order by rand() limit 5;