Click here to get back home

inserting unique value

 HomeNewsGroups | Search
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
inserting unique value Rune Zedeler 06-21-2007
Posted by Rune Zedeler on June 21, 2007, 9:20 am
Please log in for more thread options
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

Posted by lark on June 22, 2007, 10:42 am
Please log in for more thread options
== 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

Posted by Rune Zedeler on June 22, 2007, 12:24 pm
Please log in for more thread options
lark skrev:

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

Thanks, works! :+)

-Rune

Similar ThreadsPosted
varchar and unique December 19, 2005, 8:13 am
getting unique records November 23, 2006, 9:58 am
Inserting variables in mySQL table! June 25, 2005, 9:11 am
inserting current date and time July 20, 2005, 11:36 pm
Inserting records to MYSQL using ODBC May 15, 2006, 4:57 pm
Creating an unique record id ?? October 9, 2005, 1:15 pm
Returning unique records October 27, 2005, 12:35 pm
How to get the number of each unique items? October 28, 2005, 7:43 pm
problem in inserting unicode data in forms6i February 24, 2006, 1:56 am
update values on inserting duplicate index July 22, 2006, 11:42 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Driving a better car - Fuelzilla.com

Cabling site for homeowners and pros alike - Cabling-Design.com

Friends:

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap