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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:51:04+00:00 2026-05-21T20:51:04+00:00

I have a table used for a chat. Among others there is a field

  • 0

I have a table used for a chat. Among others there is a field called userid and a field called timesent. I need to know the latest timesent for each userid in the table, so that I can delete them from the table if they haven’t said anything for 3 minutes, in which case I will assume they are gone.

I can’t really crack this nut… How do I query.

I could of course split it up and first select all the userids and then loop through them and select top 1 timesent in my method, but I was wondering if sql alone can do the trick, so I don’t need to execute tons of queries.

  • 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-21T20:51:05+00:00Added an answer on May 21, 2026 at 8:51 pm

    To get the latest timesent per userid you can use MAX

    SELECT userid, MAX(timesent) AS timesent
    FROM your_table
    GROUP BY userid
    

    Or to do the specified delete you can use

    DELETE your_table 
    FROM   your_table y1 
    WHERE  NOT EXISTS(SELECT * 
                      FROM   your_table y2 
                      WHERE  y2.userid = y1.userid 
                             AND y2.timesent >= DATEADD(MINUTE, -3, GETDATE()))  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a table that is used for assessment-values in our tool where each
I have used this query to alter the table field: ALTER TABLE `recordstudent` CHANGE
We have a table containing coordinates, among other things. We used to store these
I have table that doesn't need a specific field to be the primary key.
I have this much: A table which used to store the Folders. Each folder
Basically I have a table which is used to hold employee work wear details.
I have this JSF table which is used to display data. I want to
I have a huge table that is mainly used for backup and administrative purposes.
I have a pretty common layout issue that I have traditionally used a table
I have used JQuery for a small animation work: a table #photos contains 9

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.