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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:13:17+00:00 2026-05-31T11:13:17+00:00

My database table is something like this: #tblMain ID Value CreatedDate ________________________________________ 1 25

  • 0

My database table is something like this:

#tblMain
ID     Value  CreatedDate
________________________________________
1      25     2011-10-11 14:00:45.910
1      20     2011-10-26 14:00:12.910
2      27     2011-10-14 14:00:32.910
2      39     2011-10-14 14:00:28.910
2      54     2011-10-17 14:00:27.910
3      67     2011-10-25 14:00:16.910
3      79     2011-10-25 14:00:02.910
4      34     2011-10-26 14:00:14.910
4      24     2011-10-26 14:00:06.910
4      88     2011-10-26 14:00:47.910
5      12     2011-10-26 14:03:14.910
5      34     2011-10-26 14:04:06.910
5      55     2011-10-26 14:04:47.910

I’ll get a list of IDs from a different table. So now I want to join the above table to this table based on ID, in such a way that I’ll get 1 row for every distinct ID with a value field from the row with MIN(CreatedDate) i.e. oldest value for that particular ID. i.e. for every row, the selected row would be :

SELECT TOP(1) * from #tblMain ORDER BY CreatedDate ASC where ID = 1

SELECT TOP(1) * from #tblMain ORDER BY CreatedDate ASC where ID = 2...and so on.

Thus, my output should be like this:

ID  Value  CreatedDate               X   Y   Z(other columns from other tables)
_______________________________________________________________________________
1   25     2011-10-11 14:00:45.910
2   39     2011-10-14 14:00:28.910
3   79     2011-10-25 14:00:02.910
4   24     2011-10-26 14:00:06.910
5   12     2011-10-26 14:03:14.910

Trust me, I’ve tried my best to present my requirements as clearly as I possibly can, still if there’s something unclear, let me know. Expecting a quick response. Thanks.

  • 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-31T11:13:18+00:00Added an answer on May 31, 2026 at 11:13 am

    Try:

    select m.ID, m.Value, m.CreatedDate, o.x, o.y, o.z
    from (select tM.*, row_number() over (partition by ID order by CreatedDate) rn
          from #tblMain tM) m
    left join otherTable o on m.ID = o.ID
    where m.rn=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The situation is something like this: PostgreSQL Database table has a field dateAdded which
Well i take from my database table something like: $datetime=2012-01-12 00:00:00 i want to
I got a database table that looks something like this: | id | clock
If I have the name of a database table like this: string tableName =
how to make a good MySQL Database Table Structure from this XML-Code? <xml> <product>
I've done a query like this : SELECT Code, kind, SUM(valP) AS value FROM
In a database table with a structure like this : Table 1 Name |
I have a table something like this: Product SellingPrice Cost Profit Product 1 49
I have a datatable, transformersDT, populated with data from a database table. I'd like
I need to create a database table to store different changelog/auditing (when something was

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.