How do I select 5 random rows from the 20 most recent rows?

user1413341

I want to select 5 random rows from a table but only from the 20 most recent rows. I know the 2 statements separately would be something like:

SELECT * FROM table ORDER BY RAND() LIMIT 5
SELECT * FROM table ORDER BY date DESC LIMIT 20

How would I combine these 2 statements so it will select 5 random rows from the 20 most recent rows? Thanks.

Ray

Use an nested select

 SELECT foo.* FROM (SELECT * FROM table ORDER BY date DESC LIMIT 20 ) as foo 
         ORDER BY RAND() LIMIT 5

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to select the most recent rows from tables

From Dev

How to select the most recent rows from tables

From Dev

In Postgres, how do I select rows from my table with the most recent date?

From Dev

Select the most recent 5 rows based on date

From Dev

Select most recent rows

From Dev

Select rows with most recent CreatedDate

From Dev

In T-SQL How Can I Select Up To The 5 Most Recent Rows, Grouped By An Identifier, If They Contain A Specific Value?

From Dev

How can I Select N most recent rows with unique column values

From Dev

How to select top 5 after 20 rows

From Dev

How to select top 5 after 20 rows

From Dev

How can I select 2 different random rows from a table?

From Dev

How do I select the most recent records from a table full of duplicates

From Dev

In MariaDB how do I select the top 10 rows from a table?

From Dev

SQL Query where I get most recent rows from timestamp from another table

From Dev

How do I grab the most recent price change from table

From Dev

select most recent rows for duplicate groups with data.table in R

From Dev

PANDAS select rows that contain most recent observation of pairing

From Dev

select a random rows from table

From Dev

Select random rows from table

From Dev

listing rows with the most recent date

From Dev

Getting the most recent rows in mysql

From Dev

Update the value of older rows with the most recent rows

From Dev

How do I select top rows in SQL

From Dev

How do I select rows into columns?

From Dev

How do I select rows that correspond to a rowspan?

From Dev

Delete all rows from account, except most recent eleven

From Dev

MYSQL - Selecting most recent time from 2 rows

From Dev

MYSQL:: Selecting rows from table without the most recent ones

From Dev

How to identify and delete duplicate rows, except for most recent

Related Related

  1. 1

    How to select the most recent rows from tables

  2. 2

    How to select the most recent rows from tables

  3. 3

    In Postgres, how do I select rows from my table with the most recent date?

  4. 4

    Select the most recent 5 rows based on date

  5. 5

    Select most recent rows

  6. 6

    Select rows with most recent CreatedDate

  7. 7

    In T-SQL How Can I Select Up To The 5 Most Recent Rows, Grouped By An Identifier, If They Contain A Specific Value?

  8. 8

    How can I Select N most recent rows with unique column values

  9. 9

    How to select top 5 after 20 rows

  10. 10

    How to select top 5 after 20 rows

  11. 11

    How can I select 2 different random rows from a table?

  12. 12

    How do I select the most recent records from a table full of duplicates

  13. 13

    In MariaDB how do I select the top 10 rows from a table?

  14. 14

    SQL Query where I get most recent rows from timestamp from another table

  15. 15

    How do I grab the most recent price change from table

  16. 16

    select most recent rows for duplicate groups with data.table in R

  17. 17

    PANDAS select rows that contain most recent observation of pairing

  18. 18

    select a random rows from table

  19. 19

    Select random rows from table

  20. 20

    listing rows with the most recent date

  21. 21

    Getting the most recent rows in mysql

  22. 22

    Update the value of older rows with the most recent rows

  23. 23

    How do I select top rows in SQL

  24. 24

    How do I select rows into columns?

  25. 25

    How do I select rows that correspond to a rowspan?

  26. 26

    Delete all rows from account, except most recent eleven

  27. 27

    MYSQL - Selecting most recent time from 2 rows

  28. 28

    MYSQL:: Selecting rows from table without the most recent ones

  29. 29

    How to identify and delete duplicate rows, except for most recent

HotTag

Archive