2

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

Ahmet Aytanozu
  • 111
  • 2
  • 9

2 Answers2

2

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
Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

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;
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76