Connecting Tech Pros Worldwide Help | Site Map

inserting unique value

  #1  
Old June 21st, 2007, 02:25 PM
Rune Zedeler
Guest
 
Posts: n/a
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
  #2  
Old June 22nd, 2007, 03:45 PM
lark
Guest
 
Posts: n/a

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
  #3  
Old June 22nd, 2007, 05:25 PM
Rune Zedeler
Guest
 
Posts: n/a

re: inserting unique value


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

-Rune
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generate Unique Number in DGTT situ answers 1 June 27th, 2008 08:21 PM
How to seed or increment NEWID() value sujathaeeshan answers 1 February 18th, 2008 10:09 AM
traversing the tree and assigning the unique value for each node flavourofbru answers 1 November 19th, 2007 08:29 AM
Error checking for unique value in database table? Phil Latio answers 10 May 25th, 2007 05:35 AM