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

The Archive Base Latest Questions

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

I have the following table Id col1 col2 col3 1 c 2 m 2

  • 0

I have the following table

Id  col1 col2 col3
1    c    2     m
2    c    3     6
2    b    d     u
3    e    6     9
4    1    v     8
4    2    b     t
4    4    5     g

As you can see, there are duplicate value in id column, 2 and 4. I only want to select rows with unique id value and ignore the following rows with duplicate id value. I just want to keep the first of the rows with duplicate values

1    c    2     m
2    c    3     6
3    e    6     9
4    1    v     8

There is FK constraint, so I cannot delete rows with duplicate values.

I am using SQL SERVER 2008 R2

Any reply will be appreciated.

  • 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-24T10:03:50+00:00Added an answer on May 24, 2026 at 10:03 am

    You can use row_number to number each row with the same id. Then you can select only the first row per id:

    select  *
    from    (
            select  row_number() over (partition by id order by col1, col2, col3) rn
            from    YourTable
            ) as SubQueryAlias
    where   rn = 1
    

    The subquery is required because SQL Server doesn’t allow row_number directly in the where clause.

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

Sidebar

Related Questions

Assume I have the following style table, col1 col2 and col3 have same value
I have the following query (MySQL): SELECT col1, col2 FROM database1.table ->WHERE col3 !=
I have the following MySQL table: col1 col2 col3 col4 col5 A abc val2
I have the following table: Col1 Col2 A ... A ... A B B
I have a table with the following Table1 col1 col2 ------------ 1 A 2
I have a table with the following structure id(int) | col1(int) | col2(int) |
I have a table which looks like Col1 col2 col3 col4 col5 1 5
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
I have a query like queryStr := 'SELECT col1, col2, col3, col4 FROM Table1
Assume you have the following update: Update table set col1 = func(col2) where col1<>func(col2)

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.