Solved

how to get distinct row when use together with ROW_NUMBER()?

Posted on 2011-03-15
4
504 Views
Last Modified: 2012-08-14
I try to get a list of distinct name from the query below:

Select distinct [rodnee_WISDAssetsInvRemedy].[CI_NAME], ROW_NUMBER() OVER ( Order By [rodnee_WISDAssetsInvRemedy].[CI_NAME] Asc  ) as 'RowNum'
FROM rodnee_WISDAssetsInvRemedy

but it only gave me duplicated names.
104LMWC                      1
104LMWC                      2
ADMHXP01      3
ADMHXP01      4
AIBSFIBCPAPP1      5
AIBSFIBCPAPP1      6
AIBSFIPRODAPP1      7
AIBSFIPRODAPP1      8
AIBSFIUATAPP1      9
AIBSFIUATAPP1      10

Very appreciated for your help!!!
0
Comment
Question by:jssong2000
4 Comments
 
LVL 5

Expert Comment

by:KGNickl
ID: 35141102
I believe its returning unique combinations of both name and row number.
0
 
LVL 9

Expert Comment

by:joshbula
ID: 35141237
SELECT (Select distinct [rodnee_WISDAssetsInvRemedy].[CI_NAME],
FROM rodnee_WISDAssetsInvRemedy ) As CI_NAME, Row_Number(), OVER ( Order By [rodnee_WISDAssetsInvRemedy].[CI_NAME] Asc  ) as 'RowNum',
0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 35141297
why not simply

Select [rodnee_WISDAssetsInvRemedy].[CI_NAME], ROW_NUMBER() OVER ( Order By [rodnee_WISDAssetsInvRemedy].[CI_NAME] Asc  ) as 'RowNum'
FROM rodnee_WISDAssetsInvRemedy
group by [rodnee_WISDAssetsInvRemedy].[CI_NAME]
0
 

Author Closing Comment

by:jssong2000
ID: 35141590
Thank you very much!!!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
Help with simplifying SQL 6 51
Strange msg in the SSMS pane 13 50
designing in object programming 12 42
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now