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 974645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:27:57+00:00 2026-05-16T03:27:57+00:00

I have a table that is is sorted 1st by Reminder Date then ID

  • 0

I have a table that is is sorted 1st by Reminder Date then ID

Table Looks like:

ID | remind_date 
1     2011-01-23
2     2010-02-21
4     2011-04-04
5     2011-04-04
6     2009-05-04

I am using a PHP front end to move forward and back thur the records. I want to have forward and back buttons but i am running into a problem with the 2 reminder dates that are the same.

Just to note the ID’s are NOT in order, they are here but in the actual database they are mixed up when sorting by reminder_date

The select statement i am using is: ($iid is the current record i am on)

SELECT id FROM myDB.reminders where remind_date > (SELECT remind_date FROM myDB.reminders where id=$iid)  order by remind_date ASC LIMIT 1

So what happens when i get to the dates that are the same its skips over one because its asking for remind_date >.

If i use remind_date >= it returns the current record. My solution was then to use limit 2 and check via PHP to if the 1st record = my current ID, if it did use the next one. but what it there are 3 dates the same or 4 etc..

I also thought about using the ID field but since they are out of order i can’t add in a ID > $iid.

Any ideas? it works great except for 2 dates that are the same.

  • 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-05-16T03:27:58+00:00Added an answer on May 16, 2026 at 3:27 am

    You might be able to use this:

    SELECT ID, remind_date
    FROM
    (
        SELECT @prev_id := -1
    ) AS vars
    STRAIGHT_JOIN
    (
        SELECT
            ID,
            remind_date,
            @prev_id AS prev_id,
            @prev_id := id
        FROM myDB.reminders
        ORDER BY remind_date, ID
    ) T1
    WHERE prev_id = $iid
    

    Here is a test of the above with your test data from your comment:

    CREATE TABLE Table1 (ID INT NOT NULL, remind_date DATE NOT NULL);
    INSERT INTO Table1 (ID, remind_date) VALUES
    (45, '2011-01-14'),
    (23, '2011-01-22'),
    (48, '2011-01-23'),
    (25, '2011-01-23'),
    (63, '2011-02-19');
    
    SELECT ID, remind_date
    FROM
    (
        SELECT @prev_id := -1
    ) AS vars
    STRAIGHT_JOIN
    (
        SELECT
            ID,
            remind_date,
            @prev_id AS prev_id,
            @prev_id := id
        FROM table1
        ORDER BY remind_date, ID
    ) T1
    WHERE prev_id = 25
    

    Result:

    ID  remind_date
    48  2011-01-23
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that looks like that: The rows are sorted by CLNDR_DATE
I have a table that looks something like this: ________________________ |id|value|date|approved| ----------------------- What I
I have a table that looks something like this: word big expensive smart fast
I have some data in a table that looks like this: Adam $50 Evan
I have a table that looks like this: CREATE TABLE [dbo].[StudentTime] ([StudentTimeID] [int] NOT
I have a table that I've made sortable using the jQuery plugin Tablesorter 2.0
I'm using SQL Server 2005. I have a temporary sorted table ( Table_A )
There is state table that have statename and circode but they are not sorted
I've a table that looks like: id | user_id | activity_id | activity_type |
I have a table that got into the db_owner schema, and I need it

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.