Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find id number

Posted on 2011-09-29
8
Medium Priority
?
302 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 128 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 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 248 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 124 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 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 248 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

722 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