List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:July 15 2007 2:35am
Subject:Re: New error to me...
View as plain text  
At 6:53 PM -0700 7/14/07, Steffan A. Cline wrote:
>I was trying to reduce a set of queries and ran into this:
>
>
>insert into forums (forum_reply_id, forum_dev_id, forum_subject,
>forum_message) values (0, 1, (select forum_subject from forums where
>forum_id=3 ), "I figured this one needed a reply too.")
>
>yields:
>
>error: You can't specify target table from 'forums' for update in from
>clause
>
>I read somewhere online when they referenced 4.x that said you cannot do
>subqueries in an update. Is this true of 5.x ?

You can do subqueries *unless* you're selecting from the same table
that you're inserting into.

http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

(You're not quite using INSERT INTO ... SELECT syntax, but what
you're doing appears to be effectively equivalent.)

-- 
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com
Thread
New error to me...Steffan A. Cline15 Jul
  • Re: New error to me...Mogens Melander15 Jul
    • Re: New error to me...Steffan A. Cline15 Jul
  • Re: New error to me...Paul DuBois15 Jul