MySQL Forums
Forum List  »  Newbie

Re: Referencing other columns at INSERT
Posted by: Ramalingam Chelliah
Date: August 29, 2004 10:39PM

If you need only the primary key ( Auto incrementing) value in
the composite field then it will work what ever the value of the other columns be..

But if you like to use other column values(previous) in the composite field ....
like instead of 'somethingfancy' you want to have previous value of
'data1' field then you can have this query

If you want 'name' field to have previous values 'data1_ID'

INSERT ...SELECT statement

In version 4.0.18

mysql> INSERT INTO sometable
SELECT 'blah1','blah2','2004-08-26',CONCAT_WS('_',data1,ID+1)
WHERE ID=last_insert_id();

You can not use same table name in INSERT and SELECT statements
in versions <4.0.14

But try to use alias names for table in SELECT query


We Learn the Most When we have to Invent

Options: ReplyQuote

Written By
Re: Referencing other columns at INSERT
August 29, 2004 10:39PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.