Solved

Find id number

Posted on 2011-09-29
8
279 Views
Last Modified: 2012-05-12
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
Comment
Question by:VBdotnet2005
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 15

Expert Comment

by:Eyal
ID: 36817738
you want to add identity column? or just number the rows?
0
 

Author Comment

by:VBdotnet2005
ID: 36818307
I want to find out identiy number. Is it possible. My table right now does not have id column.
0
 
LVL 15

Expert Comment

by:Eyal
ID: 36818337
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
 

Author Comment

by:VBdotnet2005
ID: 36818665
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 32 total points
ID: 36819042
>>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
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 62 total points
ID: 36839538
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
 
LVL 10

Assisted Solution

by:John Claes
John Claes earned 31 total points
ID: 36890249
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
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 62 total points
ID: 36890258
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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.

705 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now