Hello all,

I've tried the following sql queries:

mysql> create table a(id int unsigned not null auto_increment primary key,
name text);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into a values(null, 'one'), (null, 'two');
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select last_insert_id() from a;
+------------------+
| last_insert_id() |
+------------------+
|                1 |
|                1 |
+------------------+
2 rows in set (0.01 sec)

#I've tried a second time:
mysql> select last_insert_id() from a;
+------------------+
| last_insert_id() |
+------------------+
|                1 |
|                1 |
+------------------+
2 rows in set (0.00 sec)

#I've tried to put a limit clause to see the last inserted ID only once:
mysql> select last_insert_id() from a limit 1;
+------------------+
| last_insert_id() |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)

#I've tried a second time and the value is still "1"
mysql> select last_insert_id() from a limit 1;
+------------------+
| last_insert_id() |
+------------------+
|                1 |
+------------------+
1 row in set (0.00 sec)

#Now I've tried to find the last inserted ID by using "where id is null" but
...
mysql> select id from a where id is null;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

#The first trial was successfully, but the second not:
mysql> select id from a where id is null;
Empty set (0.01 sec)

#And from this point on, I get only empty responses.
Please tell me why.

And BTW, if I insert more records in a single query, how can I find the real
last one?
Is the only solution counting the number of new entered records, and adding
this number to the number returned by the last_insert_id() function?

Thank you.



Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [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