Updating a select statement.

This is a discussion on Updating a select statement. within the MySQL Database forums, part of the Database Forums category; Hello, So I'm trying to update a select statement. Here's my query UPDATE (SELECT a.id, a.colonize, ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-12-2006
Ryan Knopp
 
Posts: n/a
Default Updating a select statement.

Hello,

So I'm trying to update a select statement. Here's my query



UPDATE
(SELECT a.id, a.colonize, b.*
FROM planets AS a, minerals AS b
WHERE a.id = b.planid
AND a.colonize IS false) AS table1

SET n = n + ( nC * ( 5 /3600 ) /100 ) ,
t = t + ( tC * ( 5 /3600 ) /100 ) ,
d = d + ( dC * ( 5 /3600 ) /100 ) ,
m = m + ( mC * ( 5 /3600 ) /100 )



This is the error I get
#1288 - The target table table1 of the UPDATE is not updatable.

How do i go about making that Select statement updatable? Should I use
Join will that help?
Reply With Quote
  #2 (permalink)  
Old 12-12-2006
Nicholas Sherlock
 
Posts: n/a
Default Re: Updating a select statement.

Ryan Knopp wrote:
> UPDATE
> (SELECT a.id, a.colonize, b.*
> FROM planets AS a, minerals AS b
> WHERE a.id = b.planid
> AND a.colonize IS false) AS table1
>
> SET n = n + ( nC * ( 5 /3600 ) /100 ) ,
> t = t + ( tC * ( 5 /3600 ) /100 ) ,
> d = d + ( dC * ( 5 /3600 ) /100 ) ,
> m = m + ( mC * ( 5 /3600 ) /100 )
>
> This is the error I get
> #1288 - The target table table1 of the UPDATE is not updatable.


I don't think that you can update a Select? Maybe you can:

UPDATE a,b
SET n = n + ( nC * ( 5 /3600 ) /100 ) ,
t = t + ( tC * ( 5 /3600 ) /100 ) ,
d = d + ( dC * ( 5 /3600 ) /100 ) ,
m = m + ( mC * ( 5 /3600 ) /100 )
WHERE a.id = b.planid AND a.colonize IS false

Cheers,
Nicholas Sherlock

--
http://www.sherlocksoftware.org
Reply With Quote
  #3 (permalink)  
Old 12-13-2006
Ryan Knopp
 
Posts: n/a
Default Re: Updating a select statement.

Nicholas Sherlock wrote:
> Ryan Knopp wrote:
>> UPDATE
>> (SELECT a.id, a.colonize, b.*
>> FROM planets AS a, minerals AS b
>> WHERE a.id = b.planid
>> AND a.colonize IS false) AS table1
>>
>> SET n = n + ( nC * ( 5 /3600 ) /100 ) ,
>> t = t + ( tC * ( 5 /3600 ) /100 ) ,
>> d = d + ( dC * ( 5 /3600 ) /100 ) ,
>> m = m + ( mC * ( 5 /3600 ) /100 )
>>
>> This is the error I get
>> #1288 - The target table table1 of the UPDATE is not updatable.

>
> I don't think that you can update a Select? Maybe you can:
>
> UPDATE a,b
> SET n = n + ( nC * ( 5 /3600 ) /100 ) ,
> t = t + ( tC * ( 5 /3600 ) /100 ) ,
> d = d + ( dC * ( 5 /3600 ) /100 ) ,
> m = m + ( mC * ( 5 /3600 ) /100 )
> WHERE a.id = b.planid AND a.colonize IS false
>
> Cheers,
> Nicholas Sherlock
>

Thanks, That works!!!!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:33 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0