James Black wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I would like to set one column to point to the auto-incrementing index
of the last comment in the database for my application, but I am getting
an error when I run my test, and so I wonder if what I am trying to do
is possible.

My SQL command is:
INSERT INTo comments VALUES(0, 1, NULL, 'testuser', 'this is a test
comment', (SELECT max(idx) FROM comments WHERE sourceid=1))

Try :

Insert into comments(list of you fields here )
select 0,1,null,'testuser','testcomment',max(idx) from comments where sourceid=1;


but querying max(idx) is a bad idea. you could get the last inserted id with the following command :
SELECT last_insert_id() from comments LIMIT 1;


the last_insert_id is available on a per connection basis.

but why are you inserting back in comments a field from comments ???

--
Philippe Poelvoorde
COS Trading Ltd.

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to