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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:49:36+00:00 2026-06-06T19:49:36+00:00

I am losing my touch here. In the old days I would come up

  • 0

I am losing my touch here. In the old days I would come up with a super T-SQL query,

Select t1.Number, t1.TransactionType, t1.Description, t1.Vendor,
(Select max(t2.BatchId) From table2 t2
 Where t1.Number=t2.Number and t1.TransactionType=t2.TransactionType
 Group By t2.number,t2.transactiontype) As BatchId
From table1 t1

I need a second column from table2. Column is called “Result”.

Example:

table1:
Number, TransactionType, Description, Vendor
1, Type1, Test1, Vendor1
2, Type1, Test2, Vendor2
1, Type2, Test3, Vendor3
3, Type2, Test1, Vendor2

table2:
Number, TransactionType, BatchId, Result
1, Type1, 12, error1
1, Type1, 4, error2
1, Type2, 8, success
3, Type2, 7, success

wanted ResultSet:
Number, TransactionType, Description, Vendor, BatchId, Result
1, Type1, Test1, Vendor1, 12, error2
2, Type1, Test2, Vendor2, null, null
1, Type2, Test3, Vendor3, 8,success
3, Type2, Test1, Vendor2, 7,success

The posted query takes care of the first 5 columns. Now how about that last column?

  • 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-06T19:49:37+00:00Added an answer on June 6, 2026 at 7:49 pm
    select t1.Number, t1.TransactionType, t1.Description, t1.Vendor, t2.BatchId, t2.Result
    from table1 t1
    left join
    (
      select t2.TransactionType, t2.number, t2.Result, t2.BatchId,
        row_number() over (partition by t2.number, t2.TransactionType order by t2.BatchId desc) as BatchNumber
      from table2 t2
    ) t2 on t1.Number = t2.Number
      and t1.TransactionType = t2.TransactionType
      and t2.BatchNumber = 1
    

    If you can be sure that for each row from t1 you have related rows in t2 then it will be better to replace left join with inner join.

    UPD There was an error which was correctly noticed in the comments. I’ve changed the query to the right version.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm losing hair on a stupid query. First, I would explain what's its goal.
I feel like I'm losing my mind here. I've peeled back the css layer
I am losing my mind here. Im looking at a beginners OAuth php package
Ok I'm losing on this one. I have an NHibernate query that looks something
I am somewhat losing my mind here... I have the following code: <script id=myTemplate
I'm losing it here.. I am now extremely confused about how this loop works.
I'm losing days with this strange problem, I double checked everything but my selectOneMenu
I think I'm losing my mind here. This is the code. (It's a simplified
I'm losing my mind here. I have a conflict getting cloud zoom to work
I'm losing my mind on this one. My last question answered a syntax issue,

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.