Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. set row number in select query

set row number in select query

Scheduled Pinned Locked Moved Database
database
4 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nainakarri
    wrote on last edited by
    #1

    Hi I have a table with duplicate rows and distinct id. I have written a select query using distinct and selecting only required fields to avoid duplicates. Select dictinct(occassion), startdate from table1 Now what i want is to give unique row number to each distict row For this i tried as below but could not succeed Declare @num int set @num =0 select (set @num = @num+1) as num, dictinct(occassion), startdate from table1 After search in google , i got row_number(). But this i am unable to use as i am using distinct. Can u pls let me know how i can achieve this. Thanks in advance Naina

    Naina

    _ 1 Reply Last reply
    0
    • N nainakarri

      Hi I have a table with duplicate rows and distinct id. I have written a select query using distinct and selecting only required fields to avoid duplicates. Select dictinct(occassion), startdate from table1 Now what i want is to give unique row number to each distict row For this i tried as below but could not succeed Declare @num int set @num =0 select (set @num = @num+1) as num, dictinct(occassion), startdate from table1 After search in google , i got row_number(). But this i am unable to use as i am using distinct. Can u pls let me know how i can achieve this. Thanks in advance Naina

      Naina

      _ Offline
      _ Offline
      _Damian S_
      wrote on last edited by
      #2

      What are you going to do with the unique row number? How will it assist you? Where are you using it?

      I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

      N 1 Reply Last reply
      0
      • _ _Damian S_

        What are you going to do with the unique row number? How will it assist you? Where are you using it?

        I don't have ADHD, I have ADOS... Attention Deficit oooh SHINY!! Booger Mobile (n) - A bright green 1964 Ford Falcon - our entry into the Camp Quality esCarpade!! Do something wonderful - make a donation to Camp Quality today!!

        N Offline
        N Offline
        nainakarri
        wrote on last edited by
        #3

        Hi Thanks for the reply. It is very useful for me. As i will use it in my web page (front end) where other functionality related to this unique number is related to. Please help me to get this. Regards Naina

        Naina

        C 1 Reply Last reply
        0
        • N nainakarri

          Hi Thanks for the reply. It is very useful for me. As i will use it in my web page (front end) where other functionality related to this unique number is related to. Please help me to get this. Regards Naina

          Naina

          C Offline
          C Offline
          Coding C
          wrote on last edited by
          #4

          Cant you just use ID in the record from table itself?

          Coding C# ExciteTemplate

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups