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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:01:37+00:00 2026-06-10T21:01:37+00:00

I have a bit of a problem. I need to select a status, from

  • 0

I have a bit of a problem. I need to select a status, from a userID, in our database. The problem is, each userID has multiple rows, with different datestamps. To keep a history, in the database.

I’ve tried with group by UserID, but it will give me multiple rows, on some users, instead of ONLY the latest row, which is what I want.

This is my query:

select status, userid from EmployeeTable 
where UserId in ('nis','rele')
and asofdate in 
(select max(asofdate) from 
EmployeeTable
where userid in ('nis','rele')
group by userid
)

So the EmployeeTable has the AsOfDate column, which is basically the updated-date. So I only want the row, with the highest AsOfDate, for a particular UserID.
What am I doing wrong?
I am guessing it has to do with me using the in clause. The more userid’s I put in there, the more userid’s will output multiple rows, but I need to be able to select multiple users at once, for performance.

  • 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-10T21:01:39+00:00Added an answer on June 10, 2026 at 9:01 pm

    What you are doing wrong is that you are checking for specific users and specific dates, but there is no connection between each user and their corresponding date. If a user has a record that matches the latest date of another user, you will get that record also.

    Get the user id and their corresponding latest date, then join against the table again to get the status value for that record.

    select e.status, e.userid from EmployeeTable e
    inner join (
      select userid, max(asofdate) as d
      from EmployeeTable
      where userid in ('nis','rele')
      group by userid
    ) u on u.userid = e.userid and u.d = e.asofdate
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bit of a unique problem with an upcoming project; I need
I have a bit of problem when trying to validate my page as HTML5.
I have a bit of a problem that I can't seem to code my
I have a bit of a problem. I am trying to do the following
I have a bit of a problem building my project. I'm getting the bellow
I have a bit of a problem here. I have a third party ActiveX
So, I have a bit of a problem. I'm trying to convert an array
I'm quite new to MediaWiki, and now I have a bit of a problem.
I have a bit of a strange problem. I have a music app that
I have a bit of a unique problem. I am registering a dll as

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.