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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:05:41+00:00 2026-05-27T00:05:41+00:00

I am stuck in a sql query. I have data like: IdentityId ProductId TypeId

  • 0

I am stuck in a sql query. I have data like:

IdentityId  ProductId   TypeId   Rating
3           1             1      9
7           1             2      3
9           500           1      7
2           500           2      5
8           777           4      5
12          777           3      8
11          999           4      1

I need to the maximum Rating of each Product + i need the typeId associated with that Rating.

So the Product 1 have the maximum Rating 9 & the TypeId associated is 1

Product 500 have the maximum Rating 7 & the TypeId associated is 1

Product 777 have the maximum Rating 8 & the TypeId associated is 3

Product 999 have the maximum Rating 1 & the TypeId associated is 4

like below output:

ProductId   TypeId   Rating
1           1        9
500         1        7
777         3        8
999         4        1

Please ask me if the question is not clear.

Thanks for your valuable time & 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-27T00:05:41+00:00Added an answer on May 27, 2026 at 12:05 am
    declare @T table
    (
      IdentityId int,
      ProductId int,
      TypeId int,
      Rating int
    )
    
    insert into @T values  
    (3,           1,             1,      9),
    (7,           1,             2,      3),
    (9,           500,           1,      7),
    (2,           500,           2,      5),
    (2,           777,           4,      5),
    (12,          777,           3,      8),
    (2,           999,           4,      1)
    
    ;with C as
    (
      select ProductId,
             TypeId,
             Rating,
             row_number() over(partition by ProductID 
                               order by Rating desc) as rn
      from @T
    )
    select ProductId,
           TypeId,
           Rating
    from C
    where rn = 1
    order by ProductId
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck figuring out a working SQL Query for the fallowing: I need
I have a SQL query like this: SELECT E.HESAP, B.TEKLIF_NO1 + '/' + B.TEKLIF_NO2
I have a query that selects 3 columns from a SQL table, I need
I have the following data returned buy a simple SQL query. The Number of
I've been stuck with this simple Sql query for last 3 hours and my
Kinda stuck here... I have an application with lets say 5000 rows of data
I have a column dek with the following data I like Stack Overflow site.
I have 9 fields and I need to see all the data from these
I have a query which is something like this SELECT t.category, tc.product, tc.sub-product, count(*)
So I have a SQL table that contains time-clock information like this. The number

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.