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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:06:03+00:00 2026-05-24T16:06:03+00:00

I have a table that looks like this:- TABLEA SERIAL SKU GRADE ID HA501

  • 0

I have a table that looks like this:-

TABLEA

SERIAL  SKU GRADE   ID
HA501   R2022   2   2011063
HA501   R2022   1   2011052
HA502   R2033   2   2011051
HA502   R2033   3   2011048
HA503   R2044   1   2011034
HA503   R2044   2   2011023

I wish to extract the above SERIAL, SKU & GRADE based on the latest ID, like this:

FINAL OUTPUT            
SERIAL  SKU GRADE   ID
HA501   R2022   2   2011063
HA502   R2033   2   2011051
HA503   R2044   1   2011034

I was trying to using SQL:

select 
     SERIAL, SKU, GRADE, MAX(ID) 
from tableA
group by SERIAL, SKU, GRADE

but somehow the output doesn’t seems right.

Can someone help me ?

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-24T16:06:05+00:00Added an answer on May 24, 2026 at 4:06 pm

    Should you be using SQL Server 2005 and newer, you could use a CTE with the ROW_NUMBER construct:

    ;WITH DataForLastID AS
    (
        SELECT 
            SERIAL, SKU, GRADE, ID,
            ROW_NUMBER() OVER(PARTITION BY SERIAL, SKU ORDER BY ID DESC) AS 'RowNum'
        FROM
           dbo.TABLEA
    )
    SELECT
        SERIAL, SKU, GRADE, ID
    FROM
       DataForLastID
    WHERE
        RowNum = 1
    

    This will “partition” your data by Serial,SKU,Grade and for each group of the same values, it will sequentially number the rows starting at 1, ordered by descending ID (so the largest/newest ID will be RowNum = 1).

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

Sidebar

Related Questions

I have a table, TableA, that looks like this: ColA ColB 0 20 1
I have a table that looks like this: episodes ------------------------------------------------------------ id (PK serial) |
I have a table (let's call it tableA) that looks something like this: id
I have a table that looks like this: products -------- id, product, sku, department,
I have a LaTeX table that looks like this: \begin{table}[!ht] \centering \small \caption{ \bf{Caption}}
Hi there I have an SQL table that looks like this: CREATE TABLE IF
I have a table that looks like this: nid vid tid 1 2 3
I have a table that looks like this: <table> <thead> <!-- random table headings
I have a table that looks like this: |StreetName NR| NR | |Teststreet 34|
I have a table that looks like this: id count 1 100 2 50

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.