Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-15
4
Medium Priority
?
515 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:
Ephraim Wangoya earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Screencast - Getting to Know the Pipeline

916 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