Re: Referencing other columns at INSERT
Hi,
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
(data1,data2,est_time,name)
SELECT 'blah1','blah2','2004-08-26',CONCAT_WS('_',data1,ID+1)
FROM A
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
Regards,
Ram.
We Learn the Most When we have to Invent
Subject
Written By
Posted
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.