Results 1 to 3 of 3

Thread: Row Number in SQL Database

  1. #1
    Join Date
    Nov 2008
    Posts
    85

    Row Number in SQL Database

    hi there

    I am having some query regarding sql.
    My Question is that How do I provide a distinct unique number to each field returned. I also want to prefer to do it in sql and not to create an index as the table as I don't have sole control of the table. In the below desired output description this would be RowIndex.

    SQL 2000
    Statement to add rowindex to:
    select distinct(Description) as LawSpecialty from lawspecialty

    Please help me in this sql qeury

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Row Number in SQL Database

    select * from (

    SELECT a.Description,
    Id = ( SELECT COUNT(1) FROM (SELECT DISTINCT(Description) FROM LawSpecialty ) b WHERE a.Description > b.Description ) +1
    FROM (SELECT DISTINCT(Description) FROM LawSpecialty ) A
    ) C
    where id in (1,2,3)

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Row Number in SQL Database

    ELECT ROW_NUMBER()
    OVER (ORDER BY EmployeeName) AS Row,
    EmployeeId, EmployeeName, Salary
    FROM Employees

    which will provide you as output:

    Row EmployeeId EmployeeName Salary
    -------------------------------------------
    1 1002 Alden 4000
    2 2343 Lawson 4500
    3 2004 Barbra 4800
    4 1105 Marsden 4500
    5 3116 Mac 5000

Similar Threads

  1. Replies: 3
    Last Post: 30-01-2012, 06:01 PM
  2. Replies: 3
    Last Post: 16-09-2011, 10:56 AM
  3. Replies: 6
    Last Post: 16-08-2011, 10:51 PM
  4. Replies: 5
    Last Post: 21-03-2011, 10:24 AM
  5. convert filemaker pro database to access database
    By Czack in forum MS Office Support
    Replies: 3
    Last Post: 15-04-2007, 01:06 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,559,574.29969 seconds with 16 queries