473,809 Members | 2,699 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1712
set @counter=0;
select row1, @counter:=@coun ter+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=@count er+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:=@coun ter+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.databas e.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
5678
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' , 'messagethread' , 'messageboard_id') The 'messagethreads.id' column could have multiple auto increments. Then I could easily query a messageboard with ("SELECT * FROM
5
6638
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 important to the optimizer? Example: from Northwind (with auto create stats off), I do the following:
7
12855
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 (and would be the new PK). But, I would really like to have orders with the oldest OrderDate having the smallest ID number and, for a same OrderDate, I'd to have the smallest CustomerID first. So my question is:
6
5075
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 do with the 1st column ? (Below I have a "1" in place for now). Also, Does the datase.AcceptChanges(); updates the changes to the database? Which command do I use to update the changes in dataset back to the Access database table? Thanks, Alpha...
1
2363
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 letter. If I edit the description for one record, it edits the same for all records in which I've applied the same autofill (auto lookup). I'm set up where the letters come from a lookup combo box (limit to list "Yes") and the record source for the...
6
3936
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 one item that will be numbered as the regular ms-word auto-numbering goes. In the second column, each item will be outline numbered sequentially, with the number in the column from left leading to it. For example, in the left column the single...
9
1846
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 width is 500px I need the left column have width=100px and right column have width=100px and center off course
13
37573
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 column "ContactID" does not appear to be auto-increment. I don't know how to confirm for sure that this is so. (I have installed SQL Server Management Studio, if that helps.) How can I confirm this, and how can I make ContactID auto-increment? ...
2
1696
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 record is inserted. I guess this means the identity column is incremented when you actually reconnect to the database and insert the new record there, rather than just add the record to the locally-resident DataSet, correct? And I guess this also...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.