473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

auto column

Hi
I want to select a single row called "row1" but let mysql auto
append a NON-exist column call "row2" of it. And i want that non-exist
column be auto-increment. how to?
If i "select row1 from mytable", then i get

-----------
- row1 -
-----------
- a -
- b -
- c -
- d -
-----------

but i want:
----------------------
- row1 -- row1 -
----------------------
- a - 1 -
- b - 2 -
- c - 3 -
- d - 4 -
----------------------

thanks
from Peter (cm****@hotmail.com)

Dec 30 '05 #1
3 1691
set @counter=0;
select row1, @counter:=@counter+1 as row2 from table;

The first statement intializes a variable to 0, the SQL statement
increments the counter with each row that you retrieve.

--
Chander Ganesan
Open Technology Group, Inc.
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com
MySQL training from the experts.

Dec 30 '05 #2
Hi Chander,

I tried to do something similar in SQL Server 7.0:

declare @counter int
select @counter=0
select @counter=@counter+1, field1 from table

However, I got the following error:
A SELECT statement that assigns a value to a variable must not be
combined with data-retrieval operations.

Is it possible to use the similar statement you provided in MS SQL
Server?

Thanks,
Vincent
Chander Ganesan wrote:
set @counter=0;
select row1, @counter:=@counter+1 as row2 from table;

The first statement intializes a variable to 0, the SQL statement
increments the counter with each row that you retrieve.

--
Chander Ganesan
Open Technology Group, Inc.
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com
MySQL training from the experts.


Dec 31 '05 #3
There might be an equivalent for MS SQL, but I don't know it offhand.
I spend most of my time working with PostgreSQL, MySQL and occasionally
Oracle. I assumed you were using MySQL (since this is
mailing.database.mysql ).

--
Chander Ganesan
Open Technology Group, Inc.
Phone: 877-258-8987/919-463-0999
http://www.otg-nc.com
MySQL training from the experts.

Dec 31 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Nick | last post by:
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' ,...
5
by: Jesper Jensen | last post by:
Hello group. I have an issue, which has bothered me for a while now: I'm wondering why the column statistics, which SQL Server wants me to create, if I turn off auto-created statistics, are so...
7
by: Yannick Turgeon | last post by:
Hello all, I'm using SS2K on W2k. I'v got a table say, humm, "Orders" with two fields in the PK: OrderDate and CustomerID. I would like to add an "ID" column which would be auto-increment...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
1
by: Jim | last post by:
I have a new database in which I have a form where in one field I type a letter A, B, C or D and the field next to it autofills (auto lookups) with a description associated with the specific...
6
by: orit | last post by:
I have a word document that contains a table. The table has 2 columns and hundreds of rows. I want to number the items in the table in the following way: In the first column, each cell will contain...
9
by: Neviton | last post by:
Hi I want to create one layout with 3 columns. The left and right columns should have a auto-width. The center column should have a fixed size of 300px. By example: If the browser window...
13
by: BobLewiston | last post by:
Using Visual C# 2008 Express and SQL Server 2008 Express, I would like to insert new records into database "AdventureWorks", table "Person.Contact". To my surprise, this table's int-value identity...
2
by: BobLewiston | last post by:
Most databases have multiple users. For these databases it is a good idea to auto-increment the identity column. I understand that the identity column is not incremented until the newly-created...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.