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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:43:01+00:00 2026-05-31T16:43:01+00:00

I have one table containing user sessions and another to indicate violations in the

  • 0

I have one table containing “user sessions” and another to indicate violations in the system. One possible violation is having a user logged on for more than 12 hours straight.

The tables are as followed:

notification:
+--------------+-------------+------+-----+---------+----------------+
| Field        | Type        | Null | Key | Default | Extra          |
+--------------+-------------+------+-----+---------+----------------+
| id           | int(11)     | NO   | PRI | NULL    | auto_increment |
| host_id      | int(11)     | NO   | MUL | NULL    |                |
| alert_id     | int(11)     | NO   | MUL | NULL    |                |
| event_start  | datetime    | NO   |     | NULL    |                |
| time_noticed | datetime    | NO   |     | NULL    |                |
| info         | varchar(45) | YES  |     | NULL    |                |
| seen         | int(11)     | NO   |     | NULL    |                |
+--------------+-------------+------+-----+---------+----------------+

login:
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| username | varchar(45) | NO   |     | NULL    |       |
| host_id  | int(11)     | NO   | MUL | NULL    |       |
| start    | datetime    | NO   |     | NULL    |       |
| end      | datetime    | NO   |     | NULL    |       |
| last     | int(11)     | NO   |     | NULL    |       |
+----------+-------------+------+-----+---------+-------+

The conditions I want for the result table are:
login.last = 1, login.host_id=X, end>start+12hours
and to make sure I didn’t report this instance before:
login.host_id!=notification.host_id, notification.alert_id!=Y, login.start!=notification.event_start, login.username!=notification.info
(in other words, I don’t want to get another report of the same user, on the same host, making the same violation which started at the same time)

  • 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-31T16:43:03+00:00Added an answer on May 31, 2026 at 4:43 pm
    SELECT DISTINCT username, start 
    FROM login 
    LEFT OUTER JOIN notification ON 
        (login.host_id = notification.host_id 
        AND login.start = notification.event_start
        AND login.username = notification.info) 
    WHERE 
        end>DATE_ADD(start,INTERVAL 12 HOUR) 
        AND login.host_id=$host_id 
        AND last=1 
        AND login.id IS NULL
    

    This query should use “not exist” type of search (try EXPLAIN) which is good for the query performance.
    maybe it worth to put UNIQUE KEY on notification ‘host_id,event_started,info’ and use INSERT IGNORE

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

Sidebar

Related Questions

I have a table containing user sessions, i.e. a period a user is logged
I have a table containing users... one way or another some users were doubled
I have data table containing one column as FilePath. FilePath D:\New folder\link.txt D:\New folder\SharepointMigration(Work
I have one table having ID and other attributes. How can I get list
I have one table that has sales records and another table that has additional
I have a table containing user-account permissions and I'm trying to write a query
I have three tables, table one (tableA) containing users data like name and email,
I have a MySQL table containing user submitted data. I want the administrator to
User has many Relationships In my relationships table i have a field :referee containing
I have a table containing user input which needs to be optimized. I have

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.