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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:48+00:00 2026-05-23T16:51:48+00:00

I have exhausted my wit with this problem, so I bring the challenge to

  • 0

I have exhausted my wit with this problem, so I bring the challenge to you:

--CREATING DATA:

DECLARE @CONTACTS TABLE (ID INT, NickName CHAR(10))
INSERT INTO @CONTACTS VALUES (1359,'John Smith')
INSERT INTO @CONTACTS VALUES (1360,'Ana Keller')
INSERT INTO @CONTACTS VALUES (1361,'Joshua Doe')

DECLARE @ENTERPRISES TABLE (ID INT, CON_ID INT, ASSOCIATION DATETIME)
INSERT INTO @ENTERPRISES VALUES (123,1359,Convert(datetime, '2000-10-09', 120))
INSERT INTO @ENTERPRISES VALUES (123,1360,Convert(datetime, '2000-02-21', 120))
INSERT INTO @ENTERPRISES VALUES (123,1361,Convert(datetime, '2000-04-09', 120))

--QUERYING THE DATA:
SELECT * FROM @CONTACTS C
JOIN @ENTERPRISES E ON C.ID = E.CON_ID

--THE RESULT SET OF MY DREAMS:
    1359    John Smith    123    1359    2000-10-09

What I want is an entire row of the query before, but only the one that has the maximum ASSOCIATION date for each Enterprise ID. This is only an example for the sake of clarity, my real query is much more complex, with much more columns and trillions of rows. I have tried

SELECT *,max(FOUNDING) OVER (PARTITION BY E.ID) FROM @CONTACTS C
JOIN @ENTERPRISES E ON C.ID = E.CON_ID

But it still brings all three rows. Other approaches were worse and led to the parser asking me to GROUP BY every column. I appreciate your help.

  • 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-23T16:51:49+00:00Added an answer on May 23, 2026 at 4:51 pm
    WITH cteMaxAssociation AS (
        SELECT ID, CON_ID, ASSOCIATION,
               ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ASSOCIATION DESC) AS RowNum
            FROM @ENTERPRISES
    )
    SELECT C.ID, C.NickName, ma.ID, ma.CON_ID, ma.ASSOCIATION
        FROM @CONTACTS C
            INNER JOIN cteMaxAssociation ma
                ON C.ID = ma.CON_ID
                    AND ma.RowNum = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have exhausted all avenues in trying to solve this problem and in the
I've been trying to fix this problem for a while and have exhausted all
I know this has been asked before. But I have exhausted the options given
Iv been struggling with this for a while now an I have exhausted all
I have a little problem with my website. People use this page to create
Have you managed to get Aptana Studio debugging to work? I tried following this,
I have exhausted my efforts to find any useful information about the IAuthorizeRemotingConnection interface
As a self-taught (poorly) PHP coder, I have exhausted all the trial-and-error possibilities so
I have a PLSQL table with 30 million rows and I want to update
I'm relatively new to PHP and have exhausted the internet trying to find an

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.