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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:50:20+00:00 2026-05-16T17:50:20+00:00

I have a table in SQL Server 2005, as follows, say, fields A, B,

  • 0

I have a table in SQL Server 2005, as follows, say, fields A, B, C, D

If I have the following data:

A     B     C     D

1     B1    C1    D1 -
2     B1    C1    D1 -
3     B2    C2    D2 -
4     B2    C2    D2 -
5     B2    C2    D2 -
6     B3    C3    D3 -

I want to be able to pick out the rows which are either unique (on B, C and D), or, if not unique (on B, C and D), then I would like to pick up only the row with the largest value in the A field. So, I would like to return row 2 (A=2), row 5 and row 6 in the above scenario. I would not like to use cursors if possible but set based operations.

Is there any way I can accomplish this, in a way that I can use in a stored procedure or table-function?

Thanks in advance,
Tim

  • 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-16T17:50:21+00:00Added an answer on May 16, 2026 at 5:50 pm

    Assuming that you may well have additional columns to return…

    with cte as
    (
    select a,b,c,d,
    row_number() over (partition by b,c,d order by a desc) as rn
    from yourtable
    )
    select a,b,c,d
    from cte
    where rn=1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following table and data in SQL Server 2005: create table LogEntries
On MS SQL Server 2005, I have a table that I want to replace.
i have table with filmname and actors column in sql server 2005 i want
I have a table in SQL Server 2005 which has three columns: id (int),
I have a table in a SQL Server 2005 database with a trigger that
I am using SQL Server 2005. I have a table with a text column
in context of SQL Server 2005, I have a table for which the primary
I have a SQL Server 2005 table like this: create table Taxonomy( CategoryId integer
In SQL Server 2005 I have an id field in a table that has
I have a nullable DateTime column in my SQL Server 2005 table called DateTimeDeleted.

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.