How Select Random with parent_id in mysql?

Viewed 57

I have table like this...

╔═════╦════════╦═════════════╗
║ id  ║  text  ║  parent_id  ║
╠═════╬════════╬═════════════╣
║   1 ║  test  ║           1 ║
║   2 ║  asd   ║           1 ║
║   3 ║  dsa   ║           1 ║
║   4 ║  fgh   ║           4 ║
║   5 ║  jkl   ║           4 ║
║   6 ║  kkk   ║           4 ║
║   7 ║  asas  ║           7 ║
╚═════╩════════╩═════════════╝

how to get random output like :

╔═════╦════════╦═════════════╗
║ id  ║  text  ║  parent_id  ║
╠═════╬════════╬═════════════╣
║   4 ║  fgh   ║           4 ║
║   5 ║  jkl   ║           4 ║
║   6 ║  kkk   ║           4 ║
║   7 ║  asas  ║           7 ║
║   1 ║  test  ║           1 ║
║   2 ║  asd   ║           1 ║
║   3 ║  dsa   ║           1 ║
╚═════╩════════╩═════════════╝

or

╔═════╦════════╦═════════════╗
║ id  ║  text  ║  parent_id  ║
╠═════╬════════╬═════════════╣
║   7 ║  asas  ║           7 ║
║   4 ║  fgh   ║           4 ║
║   5 ║  jkl   ║           4 ║
║   6 ║  kkk   ║           4 ║
║   1 ║  test  ║           1 ║
║   2 ║  asd   ║           1 ║
║   3 ║  dsa   ║           1 ║
╚═════╩════════╩═════════════╝

and etc....

3 Answers
Related