SearchSearch   

inserting unique value

 
   Webmaster Forums (Home) -> MySQL RSS
Next:  creating table for rails  
Author Message
Rune Zedeler

External


Since: Jun 21, 2007
Posts: 2



(Msg. 1) Posted: Thu Jun 21, 2007 3:20 pm
Post subject: inserting unique value
Archived from groups: mailing>database>mysql (more info?)

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
Back to top
lark

External


Since: Jun 15, 2007
Posts: 14



(Msg. 2) Posted: Fri Jun 22, 2007 2:42 pm
Post subject: Re: inserting unique value
Archived from groups: per prev. post (more info?)

== Quote from Rune Zedeler (rz@daimi.au.dk)'s article
> 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
Back to top
Rune Zedeler

External


Since: Jun 21, 2007
Posts: 2



(Msg. 3) Posted: Fri Jun 22, 2007 6:24 pm
Post subject: Re: inserting unique value
Archived from groups: per prev. post (more info?)

lark skrev:

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

Thanks, works! :+)

-Rune
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> MySQL
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum