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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:42:48+00:00 2026-06-13T19:42:48+00:00

I have a database with two tables: trips and days . Each entry in

  • 0

I have a database with two tables: trips and days. Each entry in days has an id that corresponds to an entry in trips.

I want to run a query that will return the trip that occurs on a provided date, and if there isn’t one that occurs on that date then return the next trip after that date. Here’s my current query (daystring is generated in code, assume it’s a valid SQL date string):

SELECT _id, number, date 
FROM trips 
INNER JOIN days ON trips._id = days.trips_id 
WHERE days.date > DATE( daystring, "start of day", "-1 day" ) 
  AND days.date < DATE( daystring, "start of day", "+1 day" );

That query only returns a result if a trip exists on the provided date though. How can I modify it to return the next trip after that date only if there isn’t one on that date?

  • 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-13T19:42:50+00:00Added an answer on June 13, 2026 at 7:42 pm
    SELECT _id, number, date FROM trips INNER JOIN days ON trips._id = days.trips_id 
    WHERE days.date > DATE( daystring, "start of day", "-1 day" ) 
    order by date Limit 1;
    

    is a quick fix. Might want an index on the date column if you don’t have one though.

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

Sidebar

Related Questions

I have an Access database that has two tables that are related by PK/FK.
I have a database two tables and a linking table that I need a
Basically I have a database with two tables, that is, Updates table and Images
I have a database that which contains two tables, links and tour. Tour is
I have a database with two tables, component_psar and tbl_info. The component_psar table has
I have a database with two tables (Table1 and Table2). Table1 has one column
I have two tables in an existing (MSSQL 2008 R2) database that are related
I have a database with two tables that are filled with data from parallel
I have a database containing two tables - one, states, contains info about each
Say I have a database with two tables: food, and whatToEat. I query the

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.