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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:59:43+00:00 2026-06-12T17:59:43+00:00

I currently got this query: SELECT `users_sessions`.`userid` `users_sessions`.`lastActive` , `users`.`firstname` FROM `users_sessions` , `users`

  • 0

I currently got this query:

SELECT 
    `users_sessions`.`userid` `users_sessions`.`lastActive` , `users`.`firstname`
FROM 
    `users_sessions` , `users`
WHERE 
    `users_sessions`.`lastActive` >= DATE_SUB( NOW( ) , INTERVAL 60 MINUTE )
AND 
    `users`.`uidNumber` = `users_sessions`.`userid`

It selects all sessions where lastActive is 1 hour ago maximum. Now, as users can have multiple sessions at the same time, I only want to select the one with the biggest lastActive value.

I know that I somehow got to use GROUP BY users_sessions.userid and then select the entry with the biggest lastActive.

How can I do this properly?

  • 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-12T17:59:44+00:00Added an answer on June 12, 2026 at 5:59 pm
    SELECT 
        `users_sessions`.`userid`, `users_sessions`.`lastActive` , `users`.`firstname`
    FROM 
        `users_sessions` , `users`
    WHERE 
        `users_sessions`.`lastActive` >= DATE_SUB( NOW( ) , INTERVAL 60 MINUTE )
    AND 
        `users`.`uidNumber` = `users_sessions`.`userid`
    GROUP BY 
        `users_sessions`.`userid`, `users_sessions`.`lastActive` , `users`.`firstname`
    HAVING
        `lastActive` = MAX(`lastActive`)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got the following query: SELECT name, GROUP_CONCAT(job SEPARATOR ','), count(*) FROM users GROUP
Currently I got this type of query generated by programmation (c#) INSERT INTO TableName
I've currently got all of this mess at the top of my ViewModels which
Currently I'm trying to make a flowchart, this is the code I've got so
I have got this regex pattern that works with my current apache log format:
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I got a string that contains the current date by using this : NSString
how to write this correctly? for($i=2;$i<5;$i++) { $items{$i} = $doc{$i}->getElementsByTagName('url'); } got an error:
I've got a model like this def upload_location(instance, filename): return 'validate/%s/builds/%s' % (get_current_user(), filename)
I've currently got a C# application that responds to HTTP requests. The body of

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.