Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:47:25+00:00 2026-06-13T10:47:25+00:00

I have a query that selects 5 rows prior to the input datetime. When

  • 0

I have a query that selects 5 rows prior to the input datetime.

When the input datetime is close to the earliest date in my table I do not get 5 results, sometimes I get 4, 3, 2, 1 or none.

Is there a way to tell get it to select the remaining missing results (say the first query got 3 results so I need another 2) from random places in the table?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:47:26+00:00Added an answer on June 13, 2026 at 10:47 am

    Assuming you want the results older than $date_selected, latest first,

    ...
    ORDER BY
      date_add<$date_selected, date_add, 0) DESC,
      RANDOM()
    LIMIT 5
    

    read as:
    Select those before the selected date by their date, then those after the selected date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this query that works fine. It selects rows into the SY.UserOptions table
I have this query that echoes all rows prior a particular date. SELECT MAX(h.date),
If I have a query that selects the top 5 rows of a table,
I have a query that selects rows in a ListView without having a limit.
I have a query that selects a bunch of rows from various tables and
I have a query that selects 3 columns from a SQL table, I need
I have a query that selects all the users from my table. Then my
I have a query that basically combines tables of actions and selects from them
I have a SELECT query that I am expecting millions of results from. I
I have a query that looks like this SELECT * from myTable WHERE Date

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.