I have a database table with quite large data. Now i want to get random 4 out of it. What i need is a query that fetches 1000 records from it and then selects random 4 out of these 1000 and gives it as a result. I think it can be done by nested query but have no idea how to do it. Please help me with some example code.
select * from
(
select * from your_table
where some_conditions
limit 1000
)
as some_aliases
order by rand()
limit 4;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.