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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:37:42+00:00 2026-06-02T14:37:42+00:00

I have a complicated query written on SQL Server 2000 which in part contains

  • 0

I have a complicated query written on SQL Server 2000 which in part contains a join onto a derived table. This table is unfortunately not returning exactly how I desired as the underlying data differs to what I expected. Say the data are like this:

USERID,OS,DATEINSTALLED
237,win,01/01/1980
237,dos,01/02/1978
237,lin,08/08/2002
132,win,03/03/1982
132,dos,03/07/2002
132,mac,03/07/2002

Then my query looked as so:

SELECT USERID, DATEINSTALLED = max(DATEINSTALLED)
FROM INSTALLATIONS
GROUP BY USERID

Which would give a result set of

237,08/08/2002
132,03/07/2002

But what I require is a result set of:

237,lin,08/08/2002
132,dos,03/07/2002

OR

237,lin,08/08/2002
132,mac,03/07/2002

I’m not really fussed if it picks up mac or dos but it must not give 3 rows; as what I need is one row per userid, with a max date and “a” valid OS for that combination. So mac or dos are valid, but win is not (for user 132).

As it’s a derived table as part of a more complicated query I need to keep it as clean and simple as possible due to execution time (source table is a few hundred thousand rows in size). As implied by the tags I’m limited to SQL Server 2000.

  • 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-02T14:37:42+00:00Added an answer on June 2, 2026 at 2:37 pm

    Try this:

    SELECT USERID, OS, DATEINSTALLED
    FROM INSTALLATIONS
    JOIN (
       SELECT USERID, DATEINSTALLED = max(DATEINSTALLED)
       FROM INSTALLATIONS
       GROUP BY USERID
    ) AS T
    ON INSTALLATIONS.USERID = T.USERID AND INSTALLATIONS.DATEINSTALLED = T.DATEINSTALLED
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a stored procedure on SQL Server 2000. I've written a complicated select
this is my first posted question. I have a fairly complicated OQL query which
I have this complicated SQL query for Oracle that I want to visualize in
I have a complicated MySQL query which takes a lot of time, selecting from
I have a quite complicated query which will by built up dynamically and is
I have quite complicated query from which I would like to create a view.
Ok SQL and Oracle gurus I have a somewhat complicated query that I'm trying
I have a little bit complicated query. I have table tbl_Categories {CategoryID, Name, CategoryId_fk}
So I have written a query that will grab an order (this is for
I have a fairly complicated SQL query with a nested subquery. When I try

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.