• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Find id number

How can I get id number in any particular row sql? My table does no have ID field.  My data is already insert to a table.
0
VBdotnet2005
Asked:
VBdotnet2005
  • 2
  • 2
  • 2
  • +2
4 Solutions
 
EyalCommented:
you want to add identity column? or just number the rows?
0
 
VBdotnet2005Author Commented:
I want to find out identiy number. Is it possible. My table right now does not have id column.
0
 
EyalCommented:
I don't understand what you need.

you want to add a new identity column to the table?
or only in the select display row numbers?

point me to the right direction you need
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
VBdotnet2005Author Commented:
I don't want add new columns. My table right now does not have id column. Maybe I am asking the wrong question. I want to find out the row # on a particular row.
0
 
Anthony PerkinsCommented:
>>I want to find out the row # on a particular row. <<
There is no such thing as a row #.  You can certainly create one, but the order will depend on the ORDER BY clause.  For example you can do something like this:
SELECT ROW_NUMBER() OVER (ORDER BY SomeColumn) Row, *
FROM YourTableNameGoesHere
ORDER BY SomeColumn
0
 
Kevin CrossChief Technology OfficerCommented:
Exactly as acperkins has just shown. Here is an explanation of how that works: http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/A_1555-Analytical-SQL-Where-do-you-rank.html

Another approach is to ADD an IDENTITY to your table. It will assign sequential number in the natural order of the rows currently.

You can try this with:

SELECT ROW_NUMBER() OVER (ORDER BY (SELECT 1)) Row, *
FROM YourTableNameGoesHere
;

But not sure that the order can be depended on to always match up to the order rows were inserted originally.
0
 
John ClaesSenior .Net Consultant & Technical AnalistCommented:
If your Table doesn't have a ID-column
Dos it have a Primary Key (can be over multiple Columns?)

The Id field is mostly used to retreive very fast the Row that is needed using this Key
And to Link the Row to other rows that needs the data of our Row (See Joins)

If your table doen's have a I field you can always check if you have a Primary Key
Using this Primary Key you can do the same (even when containing multiple Columns)

poor beggar
0
 
Kevin CrossChief Technology OfficerCommented:
Re: "Another approach is to ADD an IDENTITY to your table. It will assign sequential number in the natural order of the rows currently." I just caught that you said "I don't want add new columns." Therefore, never mind that, but the addition to what acperkins still applies. That is likely your best approach. If you do have some column that is sequential/chronological, then you can use that in the OVER(ORDER BY) clause as acperkins showed; otherwise, try the (SELECT 1).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now