Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert with select on same table.

Status
Not open for further replies.

jscott

Programmer
Nov 13, 2000
7
US
Hi, I have been working on this isnert for a while, with several differant varieties of the same code with no result except error.
I have tried-insert into abstractor(abID) select (select (concat(substring(abstractor.abFirst, 1, 1), substring(abstractor.abLast, 1, 1), abstractor.abstractorID));

as well as-insert into abstractor(abID) select (select (substring(abstractor.abFirst, 1, 1), substring(abstractor.abLast, 1, 1), abstractor.abstractorID);

and-insert into abstractor(abID) select (select concat (substring(abstractor.abFirst, 1, 1), substring(abstractor.abLast, 1, 1), abstractor.abstractorID));

all return the same message, syntax error.
Can this be done?
Jean
 
as I know after insert should't follow brackets(). If you want so, remove brackets after select or use values instead of select. Ion Filipski
1c.bmp


filipski@excite.com
 
I tried the following two with the same syntax error
insert into abstractor(abID) values (select concat (substring(abstractor.abFirst, 1, 1), substring(abstractor.abLast, 1, 1), abstractor.abstractorID));

insert into abstractor(abID) values (concat (substring(abstractor.abFirst, 1, 1), substring(abstractor.abLast, 1, 1), abstractor.abstractorID));

I am not sure the select values will work if I am trying to insert them from the same table. Does anyone know if I can do an insert select from the same table?
If so I need a clue!!!
Thanks
Jean
 
insert into xxx(a,b,c)
select x,y,z from xxx; Ion Filipski
1c.bmp


filipski@excite.com
 
One suggestion, does not an insert clause need a values section.... insert into test ( cola, colb ) VALUES ( ( select .....) ) ;

Just a thought B-)
 
Ok, I understood what the problem is. This is a recursion in the insert. use a temp table. Ion Filipski
1c.bmp


filipski@excite.com
 
Thanks, I think that is the only way.
I didn't want to have to do this every time I add new rows. I was hoping to make it automatic so to speak. When a new person is added through the site I am working on I want this field to generate itself....I want to make it an unique key field. I guess I will have to generate this field's value through my cgi before doing the inserts.
Thanks
Jean
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top