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

  • Home
  • SEARCH
  • 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 7630067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:00:14+00:00 2026-05-31T06:00:14+00:00

I have a table (in MS Access) that stores in each record the start

  • 0

I have a table (in MS Access) that stores in each record the start and end date for one event associated with an item. Multiple events may be associated with each item, and event time periods may overlap.

I will use the term ‘open event’ to mean an event that has a start date less than and an end date greater than a given date.

I would like a query that gives me the list of items that had at least one open event within a given time period, but which also have no open events at the end of the time period. Ideally, I would also like to list for each of these items the id of the last open event in the time period.

Here is a list of event records that represent some cases I need to have covered. The time period in question is 2012-03-20 to 2012-03-30:

eventId   itemId   startDate    endDate
e1        i1       2012-03-21   2012-03-23   -- event open entirely inside of time period
e2        i2       2012-03-19   2012-03-21   -- event open at start date
e3        i3       2012-03-29   2012-03-31   -- event open at end date

e4        i4       2012-03-19   2012-03-26   -- multi-event item with event open at end date
e5        i4       2012-03-22   2012-03-25
e6        i4       2012-03-29   2012-03-31
e7        i4       2012-04-01   2012-04-30

e8        i5       2012-03-19   2012-03-25   -- multi-event item with no events open at end date
e9        i5       2012-03-22   2012-03-29
e10       i5       2012-03-25   2012-03-26
e11       i5       2012-04-01   2012-04-30

e12       i6       2012-03-13   2012-03-19   -- event not in time period at all

And here are the items (and their last-open events) that I’d like to see as a result of this query:

i1, e1
i2, e2
i5, e9  -- note that e9.endDate > e8.endDate and e10.endDate, and that e11 falls after the time period in question, so is not considered the last event for the item
  • 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-31T06:00:15+00:00Added an answer on May 31, 2026 at 6:00 am

    You could left join to a subquery that lists all events that are open at the enddate. If you demand that a column from the subquery is null, you exclude all event/item combinations that match the subquery.

    select  distinct e.eventId
    ,       e.itemId
    from    Events e
    left join
            (
            select  distinct itemId
            from    Events
            where   startDate < '2012-03-30' -- Started before end
                    and '2012-03-30' < EndDate -- Closed after end
            ) oe
    on      e.itemId = oe.itemId
    where   e.startDate < '2012-03-30' -- Started before end
            and '2012-03-20' < e.EndDate -- Ended after start
            and oe.eventId is null -- Not open at end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ms access database that has one table for each photo album
I have a legacy MS Access 2007 table that contains 52 fields (1 field
In one of the ms-access table I work with we have a text field
I Have a table in Access as below SI Number Time 1.14172E+20 13:30:35 1244066650
I have an access table which has some cells as blank ( no data
I have a table in an Access 2007 database. All fields are of type
I have got a table in MS Access 2007 with 4 fields. Labour Cost
I have a question about Access.If for example I have a table with the
I have the table (Product_Id, category priority, atribute1, atribute2...) in MS Access, and I
I have a field on a table in MS Access, tblMyTable.SomeID, and I want

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.