Connecting Tech Pros Worldwide Forums | Help | Site Map

inserting unique value

Rune Zedeler
Guest
 
Posts: n/a
#1: Jun 21 '07
I need to insert a unique value into a (not auto-increment) column.
I try

insert into idtest (val) values ((select max(val) from idtest)+1);

but I get

ERROR 1093 (HY000): You can't specify target table 'idtest' for update
in FROM clause

- what is the correct way to do this?

Regards,
Rune

lark
Guest
 
Posts: n/a
#2: Jun 22 '07

re: inserting unique value


== Quote from Rune Zedeler (rz@daimi.au.dk)'s article
Quote:
I need to insert a unique value into a (not auto-increment) column.
I try
insert into idtest (val) values ((select max(val) from idtest)+1);
but I get
ERROR 1093 (HY000): You can't specify target table 'idtest' for update
in FROM clause
- what is the correct way to do this?
Regards,
Rune
how about this:

insert into idtest (val) (select (max(val)+1) from idtest);

let me know if it works for you.
--
POST BY: lark with PHP News Reader
Rune Zedeler
Guest
 
Posts: n/a
#3: Jun 22 '07

re: inserting unique value


lark skrev:
Quote:
insert into idtest (val) (select (max(val)+1) from idtest);
Thanks, works! :+)

-Rune
Closed Thread