SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 21st, 2008, 09:49 AM
mrcinfl mrcinfl is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 mrcinfl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 23 sec
Reputation Power: 0
Update Table From Same Table

I am using MySQL 5.0.51a and phpMyAdmin 2.11.4. I need to update a field in a table. I have a list of products in a table in which several hundred need to be renamed. The products that need to be renamed all end with -HOLD. I need to remove -HOLD from the products name. This is the error I get '#1093 - You can't specify target table 'prodlist' for update in FROM clause'. This is my sql:

UPDATE `prodlist` SET `prodname` = LEFT(`prodname`,LENGTH(`prodname`)-5) WHERE `prodname` IN(SELECT `prodname` AS product FROM `prodlist` WHERE RIGHT(`prodname`,5) = '-HOLD')

Could someone please tell me what I am doing wrong or how I can accomplish this? Thank you very much.

Reply With Quote
  #2  
Old April 22nd, 2008, 09:55 PM
dykebert's Avatar
dykebert dykebert is offline
Contributing User
Click here for more information. Click here for more information
 
Join Date: Apr 2008
Posts: 195 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 1 h 37 m 18 sec
Reputation Power: 1
I don't know MySQL, but your problem seems to be straight SQL

In plalin SQL, the query would be:

UPDATE `prodlist` SET `prodname` = LEFT(`prodname`,LENGTH(`prodname`)-5)
WHERE RIGHT(`prodname`,5) = '-HOLD')

Reply With Quote
  #3  
Old April 24th, 2008, 08:04 AM
mrcinfl mrcinfl is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 mrcinfl User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 23 sec
Reputation Power: 0
Quote:
Originally Posted by dykebert
I don't know MySQL, but your problem seems to be straight SQL

In plalin SQL, the query would be:

UPDATE `prodlist` SET `prodname` = LEFT(`prodname`,LENGTH(`prodname`)-5)
WHERE RIGHT(`prodname`,5) = '-HOLD')


Thank you very much dykebert. That works very nicely. I guess I was trying to make it too complicated.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Update Table From Same Table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway