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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:57:04+00:00 2026-05-23T05:57:04+00:00

Given this table : mysql> describe activity; +—————————+————-+——+—–+———+——-+ | Field | Type | Null

  • 0

Given this table :

mysql> describe activity;
+---------------------------+-------------+------+-----+---------+-------+
| Field                     | Type        | Null | Key | Default | Extra |
+---------------------------+-------------+------+-----+---------+-------+
| user_id                   | varchar(16) | NO   |     | NULL    |       |
| login_time                | int(11)     | NO   |     | NULL    |       |
| last_activity_time        | int(11)     | NO   |     | NULL    |       |
| last_activity_description | text        | YES  |     | NULL    |       |
| logout_time               | int(11)     | NO   |     | NULL    |       |
+---------------------------+-------------+------+-----+---------+-------+
5 rows in set (0.01 sec)

I want to select the most recent last_activity_time (standard Unix timestamp) for each user who is logged in (i.e has one or more rows where logout_time is not zer0).

I tried

SELECT user_id, login_time, MAX(last_activity_time) 
  FROM activity  
 WHERE logout_time="0"; 

…but that found only a single entry with two users logged in, probably because I am selecting for MAX(last_activity_time)

What I want is something like

SELECT all unique user_ids  
  SELECT each of those which has one or more entries where `logout_time` != 0  
     SELECT the maximum value of `logout_time` for each of those

all in one single SELECT statement. How can I do that?

  • 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-23T05:57:05+00:00Added an answer on May 23, 2026 at 5:57 am
    SELECT user_id, MAX(logout_time)
    FROM activity 
    WHERE logout_time <> "0" 
    GROUP BY user_id;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a table named person (in a MySQL database/schema), kind of like this one:
In the code below, created is a field in a MySQL table. This field
I have a MySQL database table with this structure: table id INT NOT NULL
I have a MySQL table with a primary key field that has AUTO_INCREMENT on.
Given a table structure like this: CREATE TABLE `user` ( `id` int(10) unsigned NOT
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
Given this table design in a web application: CREATE TABLE `invoice` ( `invoice_nr` int(10)
I just added a new field to my table in mysql and it came
I'm having trouble on generating a report in MySQL. I have this table: CREATE
I have a primary key in my mysql table which is comprised of three

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.