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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:36:02+00:00 2026-06-15T18:36:02+00:00

There is a result set where all the records are unique columns like this

  • 0

There is a result set where all the records are unique columns like this .
I only want to display the records with newer dates if there is another record which belongs to the same BusinessID.
My query to get this result is

SELECT 
  FirstName, 
  LastName,
  Department,
  StartDate,
  Title,
  PhoneNumber,
  BusinessEntityID
FROM
  (SELECT
     E.BusinessEntityID,
     H.FirstName,
     H.LastName,
     H.Title,
     H.Department,
     E.PhoneNumber,
     E.CountryRegionName,
     E.PostalCode,
     H.StartDate
   FROM 
     CS120Exam_EmployeeDepartmentHistory H
   JOIN 
     CS120Exam_Employee E
   ON 
     E.BusinessEntityID=H.BusinessEntityID ) x 
   ORDER BY BusinessEntityID

And the result is

BusinessID  FirstName LastName Department StartDate
----------- --------- -------- ---------- ----------
1           aaa       mate     staff      2002-02-02 <----- DO NOT want this 
1           aaa       mate     admin      2004-03-05
2           john      mate     admin      2001-03-06
3           sun       kent     admin      2004-03-05
4           bbb       clark    staff      2006-02-02 <----- DO NOT want this 
4           bbb       clark    admin      2009-03-05
  • 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-15T18:36:03+00:00Added an answer on June 15, 2026 at 6:36 pm

    You need a sub-select to find the latest date for each BusinessEntityID. Try this (untested, of course):

    SELECT 
      FirstName, 
      LastName,
      Department,
      StartDate,
      Title,
      PhoneNumber,
      BusinessEntityID
    FROM
      (SELECT
         E.BusinessEntityID,
         H.FirstName,
         H.LastName,
         H.Title,
         H.Department,
         E.PhoneNumber,
         E.CountryRegionName,
         E.PostalCode,
         H.StartDate
       FROM 
         CS120Exam_EmployeeDepartmentHistory H
       JOIN 
         CS120Exam_Employee E
       ON 
         E.BusinessEntityID=H.BusinessEntityID ) x 
       WHERE x.StartDate = 
         (SELECT 
            Max(cs.StartDate) 
          FROM
            CS120Exam_EmployeeDepartmentHistory cs
          WHERE
            cs.BusinessEntityID = x.BusinessEntityID)
       ORDER BY BusinessEntityID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to achieve this result there are many tutorial around like this but
Is there any way of accessing both a result set and output parameters from
I was wondering if there is a way to display only a limited number
I want the result set of a database query to have a certain order.
Is there a way to expand/get all the records of a GROUP BY and
I have two tables. First table looks like this: Table: Records rid | user
Consider i am using join on three tables to get a desired result-set... Now
Is there a 'Max # of result sets that can be displayed' when executing
Is there a way to add the select-result on the url when the pop
Is there a way to directly write result returned from TSQL / stored procedure

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.