Fox
Fox

Reputation: 103

Can I SELECT from mysql 5 values from top N(10)? (rand)

I need take from MYSQL 5 values that taked from top 10 values randomly?

Exmple: I'v 100 posts in my db and I want take 5 of them that have views number in top 10 posts. How can I do it by only one command in mysql?

Upvotes: 2

Views: 57

Answers (1)

Dimash
Dimash

Reputation: 591

SELECT * FROM 
(SELECT * FROM posts order by id DESC limit 0,10) as p1 
ORDER BY rand() limit 0,5

Please change fields according your database structure

Upvotes: 1

Related Questions