• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Display the sequence numbers on the output rows of a select in Oracle 10g

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an Employee table with a salary column. I want to find the distinct salaries in the Employee table.

SQL> select distinct salary from Employee order by salary;

It only display the distinct salaries:

1000
1100
12345
....

Now I want to put a line sequence number in front of each distinct salary. Something like:

1: 1000
2: 1100
3: 12345

How should I change the select query? I know rownum does not help here.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use "select rownum, distinct salary from emp order by salary"
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
 
Tejas Jain
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Goutham Pallipati wrote:use "select rownum, distinct salary from emp order by salary"



I got an ORA-00936 error: missing expression
 
Tejas Jain
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ireneusz Kordal wrote:Try this:



This works. Thanks.

Now what if I only want to find the 3rd highest salary?
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Todd Jain wrote:

Goutham Pallipati wrote:use "select rownum, distinct salary from emp order by salary"



I go an ORA-00936 error: missing expression



You have got an error because this query has a syntax error
- DISTINCT can appear right after SELECT only ,and can applied to the whole row,
DISTINCT cannot be applied to individual columns.

The syntax of SELECT statement is:
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!