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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:48:39+00:00 2026-06-10T10:48:39+00:00

I have a table where i store events and it has 2 fields for

  • 0

I have a table where i store events and it has 2 fields for dates. One for the start date (start_date) of the event and other for the end date (end_date).
Some events dont have end_date defined or have end_date=’1970-01-01′.

I used the following mysql query to retreive the current and future events.

SELECT * 
FROM events 
WHERE start_time >= CURDATE() 
    OR (start_time <= CURDATE() AND end_time>=CURDATE()) 
ORDER BY events.start_time;

What i would need is a query that returns the same results but ordered in a different way and according to the following way:

  • the events are ‘divided’ in two groups: the current events, and the future events. Current events are considered all the events that started in the day before the actual date (‘yesterday’) and still didn’t finished.

  • the results will show first future events, ordered ascending by start_time, and after show current events, ordered ascending by start_time.

Thanks

  • 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-10T10:48:40+00:00Added an answer on June 10, 2026 at 10:48 am
    SELECT *,
           DATEDIFF(start_time, CURDATE()) AS diff
    FROM   events
    WHERE  start_time >= CURDATE()
            OR ( start_time <= CURDATE()
                 AND end_time >= CURDATE() )
    ORDER  BY CASE
                WHEN diff > 0 THEN 0
                ELSE 1
              end,
              diff ASC;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I love NHibernate's ability to have one table to store multiple types based on
I have a table which i want to store all the outputs into one
I have one postgresql table where I store some stories from different sites. At
I have a table in which users store scores and other information about said
I have a PostgreSQL database with events. Each event has a datetime or an
I have a mysql database table that will store locations for buildings and events
I want to secure events stored in one table, which has relations to others.
I have a two tables. One table is actually populated by daily events while
I have a table that functions as an event log and stores the users
We have a table in which we store millions of small BLOBs (2-10kb). And

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.