Click here to get back home

inserting unique value

 HomeNewsGroups | Search

mailing.database.mysql - MySQL database issues discussed in this best MySQL group in USENET 

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
show/hide quoted text

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:

show/hide quoted text

Thanks, works! :+)

-Rune

Similar ThreadsPosted
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
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
Inserting a list of names in a table using stored procedure February 20, 2006, 10:02 am
lots of time taking when inserting 1000 records July 26, 2006, 2:25 am
varchar and unique December 19, 2005, 8:13 am
getting unique records November 23, 2006, 9:58 am
Creating an unique record id ?? October 9, 2005, 1:15 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
Privacy Policy