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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:02:47+00:00 2026-05-11T17:02:47+00:00

I am stuck figuring out a working SQL Query for the fallowing: I need

  • 0

I am stuck figuring out a working SQL Query for the fallowing:
I need to generate a Fire Register report (how many people are still inside the building) based on an Access database that records login/logout events along with some metadata.
The Access DB looks like this:

+----+---------------------+---------+---------+------+
| id | date                | action  | success | user |
+----+---------------------+---------+---------+------+
|  1 | 2009-04-28 02:00:00 |   login |       1 | Nick |
|  2 | 2009-04-28 03:00:00 |  logout |       1 | Nick |
|  3 | 2009-04-28 04:00:00 |   login |       1 | Nick |
|  4 | 2009-04-28 04:00:00 |  logout |       1 | Nick |
|  5 | 2009-04-28 04:00:00 |   login |       1 | Nick |
|  6 | 2009-04-28 07:00:00 |   login |       1 | John |
|  7 | 2009-04-28 07:30:00 |   login |       1 | Sue  |
|  8 | 2009-04-28 08:00:00 |  logout |       1 | John |
+----+---------------------+---------+---------+------+

During the day there can be multiple login/logout actions.
When administrator runs the report, it’s only limited for current day and needs to list all users where the last known action for this user is login and success=1, meaning that this person is currently in the building.

On the data above, Nick and Sue must be pointed out as still being inside the building.

  • 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-11T17:02:47+00:00Added an answer on May 11, 2026 at 5:02 pm

    Another approach to the problem:

    SELECT
         T1.user
    FROM
         Some_Table T1
    LEFT OUTER JOIN Some_Table T2 ON
         T2.user = T1.user AND
         T2.success = 1 AND
         T2.date > T1.date
    WHERE
         T1.success = 1 AND
         T1.action = 'login' AND
         T2.id IS NULL
    

    This assumes that you only care about successful actions. Also, if a user has two actions on the same EXACT date AND time then it might not act as expected.

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

Sidebar

Ask A Question

Stats

  • Questions 191k
  • Answers 191k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You are initializing a reference from temporary. The standard states:… May 12, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer Here's some XAML that shows how to do what you're… May 12, 2026 at 6:12 pm
  • Editorial Team
    Editorial Team added an answer HAVING works with aliases in MySQL: SELECT *, LOCATE( column,… May 12, 2026 at 6:12 pm

Related Questions

I am attempting to create new membership users in an Ektron CMS400.NET-based website by
I'm working the the image upload piece of the FCKEditor and I've got the
I'm new to Flex SDK and trying to implement a simple project using Doug
I need some help figuring out what I'm doing wrong here. I am trying

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.