Hi.

On Wed 2002-06-05 at 22:03:59 +0200, [EMAIL PROTECTED] wrote:
> Hi.
> 
> I need to have a cardinal number near each data, when I submit a query:
> 
> for example, if my table is:
> 
> +-------------+
> | example     |
> +-------------+
> | cat         |
> | dog         |
> | horse       |
> ....
> 
> I'd like to have, with a "select" statement..
> 
> +-------------+-------+
> | example     | pos   |
> +-------------+-------+
> | cat         | 1     |
> | dog         | 2     |
> | horse       | 3     |
> ....            ...
> 
[...]
> IMPORTANT NOTE: I can't add a (permanent) column with an
> "auto_increment" value; I'm writing a simple gui for mysql and I
> don't want to alter the original db..
> 
> I'm using MySQL 3.23.49
> 
> can someone help me?
[...]

IMHO, The Right Thing to do this, is to create the additional data in
your application (as you said you won't change the table).

If you want this with SQL for sure, using user-defined variables will
work:

mysql> select @a := 0;
+---------+
| @a := 0 |
+---------+
|       0 |
+---------+
1 row in set (0.00 sec)

mysql> select @a := @a + 1 AS pos, gid from config where gid>300000 limit 10;
+------+--------+
| pos  | gid    |
+------+--------+
|    1 | 300001 |
|    2 | 300002 |
|    3 | 300003 |
|    4 | 300004 |
|    5 | 300005 |
|    6 | 300006 |
|    7 | 300007 |
|    8 | 300008 |
|    9 | 300009 |
|   10 | 300010 |
+------+--------+
10 rows in set (0.00 sec)

Another approach would be to select the data into a TEMPORARY TABLE.

Bye,

        Benjamin.


-- 
[EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to